Create a MS SQL Server Connection DataLink Properties Window

J

Jay Douglas

Hello,

I'm trying to create a Data Links Property window that behaves just like
the dialog box in Visual Studio .Net for MS Sql Server connections. I've
found a lot of examples that use DataLinks classes from "Microsoft OLE DB
Service Component 1.0 Type Library" and the Connection object from ADODB.
However, when setting the connection string using these classes the
connection string always returns a really basic connection string with no
additional params.

The connection string I'm currently receiving is:
Provider=SQLOLEDB.1;Password=mypass;Persist Security Info=True;User
ID=sa;Initial Catalog=Northwind;Data Source=(local)

I would like a connection string that looks more like:
packet size=4096;user id=sa;data source=(local);persist security
info=True;initial catalog=NorthWind;password=mypass

It seems like the DataLink / Connection option isn't returning all the
parameters / properties that can be set in the "All" tab of the Data Link
Properties window.

What am I missing...

The Code:

private void launchDataPromptEdit_Click(object sender, System.EventArgs e)
{
/*
Reference DataLinks
NOTE: Reference
C:\Program Files\Common Files\System\Ole DB\OLEDB32.DLL
(Was MSDASC.dll)
SEE:
http://support.microsoft.com:80/support/kb/articles/Q225/1/32.asp
*/
MSDASC.DataLinks dataLinks = new MSDASC.DataLinksClass();
//note that a reference to:
// c:\Program Files\Microsoft.NET\Primary Interop Assemblies\adodb.dll
//is also required to read the ADODB._Connection result
ADODB._Connection connection;
//are we editing an existing connect string or getting a new one?
//connection.



if(connStr.Text == string.Empty)
{
// get a new connection string
try
{
//Prompt user for new connect string

connection = (ADODB._Connection)dataLinks.PromptNew();
//read result
connStr.Text =
connection.ConnectionString.ToString();
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
else
{
// edit connection string
connection=new ADODB.ConnectionClass();
connection.ConnectionString=this.connStr.Text;
//set local COM compatible data type
object oConnection=connection;
try
{
//prompt user to edit the given connect string
if((bool)dataLinks.PromptEdit(ref oConnection))
{
this.connStr.Text=
connection.ConnectionString;
}
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top