HowTo... Configure a connection string like a pro.
Ever wondered how to configure a connection string using the Data Link properties dialog?
Well, I have. And just last night I decided to check out exactly how to do this. Here's a simple list with all the required steps:
- Add a reference to "Microsoft OLE DB Service Component 1.0 Type Library" (it’s in the COM Tab)
- Add a reference to the Primary Interop Assembly (PIA) for ADO (Add References > adodb)
- Add the following code (for instance to a button click event handler):
1: ADODB.Connection conn = new ADODB.Connection();
2: object oConn = (object)conn;
4: MSDASC.DataLinks dlg = new MSDASC.DataLinks();
5: dlg.PromptEdit(ref oConn);
7: txtConnectionString.Text = conn.ConnectionString;
We can also pre-assign the ConnectionString property of the Connection object before we open up the Data Link dialog.
If we do this, the dialog is already filled with the configuration from the connection string.