You can add parameters to your function, for example:
// in Main:
CopySQLTable(Tbl, true, DestinationServer, DestinationDatabase, SourceServer, SourceDatabase);
// the function:
public static void CopySQLTable(string SourceTable, bool OverwriteDestinationTable,
string DestinationServer, string DestinationDatabase,
string SourceServer, string SourceDatabase)
{
. . .
}
Or you can move the variables to class level, without other adjustments:
public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{
static string DestinationServer;
static string DestinationDatabase;
static string SourceServer;
static string SourceDatabase;
public void Main()
{
// (variables moved)
. . .
The latter method depends on some aspects. Maybe the Main function can be declared static too?