
Introduction
A similar article was written on this subject but this article deals with accessing DataLinks from a .NET program to get or edit a connection string. Your project must reference DataLinks and ADODB, then execute the PromptNew
or PromptEdit
methods.
Step by step procedure
- Reference ADODB in your project. This is required to read the COM object passed back from DataLinks. This file is located here: c:\Program Files\Microsoft.NET\Primary Interop Assemblies\adodb.dll
- Reference DataLinks in your project. DataLinks used to be MSDASC.dll, but has changed to OLEDB32.DLL (see KB). This file is located here: C:\Program Files\Common Files\System\Ole DB\OLEDB32.DLL
- Create a text box and a button on a Windows Form. In the button's click event, use this code:
private void ButtonGetConnectionString_Click(object sender,
System.EventArgs e)
{
MSDASC.DataLinks dataLinks = new MSDASC.DataLinksClass();
ADODB._Connection connection;
if(this.txtConnectionString.Text==String.Empty)
{
try
{
connection = (ADODB._Connection)dataLinks.PromptNew();
this.txtConnectionString.Text=
connection.ConnectionString.ToString();
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
else
{
connection=new ADODB.ConnectionClass();
connection.ConnectionString=this.txtConnectionString.Text;
object oConnection=connection;
try
{
if((bool)dataLinks.PromptEdit(ref oConnection))
{
this.txtConnectionString.Text=
connection.ConnectionString;
}
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}