Here I suggested (very simplifiedly illustrate the problem space) for a C # console application. Database connections implement IDisposable, and this solution does not allow usingdatabase objects to be connected. Can someone suggest a more proper structure for a console application? This is a problem that I need to solve often.
class Program
{
SQLiteConnection sourceConnection;
SQLiteConnection destinationConnection;
static void Main(string[] args)
{
Program shell = new Program();
string sourceConnectionString = shell.getConnectionString(args);
string destinationConnectionString = shell.getConnectionString(args);
shell.setUpConnections(sourceConnectionString, destinationConnectionString);
shell.doDatabaseWork();
}
private void setUpConnections(string sourceConnectionString, string destinationConnectionString)
{
sourceConnection = new SQLiteConnection(sourceConnectionString);
destinationConnection = new SQLiteConnection(destinationConnectionString);
}
private void doDatabaseWork()
{
}
}
Edit:
Some people cannot understand why I want them to be member variables. Here is my use case (a bit psuedocoded) about what doDatabaseWork will do:
foreach (Row sourceRow in DBResultSet)
{
string sourceXml = sourceRow.Columns["MyColumnName"].Value;
string destinationXML = transformUsingXSLT(sourceXml);
writeToDestination(destinationXml);
}
See how I want these connections to open up for the life of this cycle?