Mar 27, 2007 at 9:43 PM
Edited Mar 27, 2007 at 9:44 PM
I am using Enterprise Library 2006 - Data Access Application block for console application. I have around 10 console applications created which needs to be run in batch mode. I am not using App.config file for those console applications created. Also I
am forced to build the connection string dynamically. Hence I didnt specify anything in the app.config file. I am using sqldatabase class for establishing the connection using the dynamically generated connection string as shown below:
dim db as new sqldatabase("server=something;UID=usrxyz;pwd=;database=something;")
Then I will be executing the sql statement by assigning it to the command object(dbCommand) as shown below:
Dim dtOutput as dataset = db.Executedataset(dbCommand)
In this way, I have achieved the following:
(a) eliminated app.config files for 10 console applications
(b) would be able to create the connection string dynamically and pass it to the sqldatabase class
Here is the question comes
What should I do if I have to establish the connection through system DSN? I am unable to establish the DSN connection "DSN=systemdsn;Uid=usrxyz;pwd=pwdxyz;" using the sqldatabase class. I believe the sqldatabase class is meant only for the sqlclient provider.
Do you guys have any other suggestions??
Please note that I have not modified anything in Data Access component.
I assume you are using the Data Source (ODBC) Administration Tool to configure the DSN, which means you will be using ODBC to connect to the database.
I set up a System DSN to my SQL Server Instance and used the following to connect to it:
GenericDatabase db = new GenericDatabase("DSN=test", OdbcFactory.Instance);
db.ExecuteDataSet(CommandType.Text, "SELECT CustomerId FROM Customers");
Since you are using ODBC, you will need to use the GenericDatabase Class and pass it an instance of your connection string.
Microsoft MVP C#