Invoking Data Link Properties for ADO.NET SqlConnection?

B

Ben Fidge

How do you invoke the Data Link Properties dialog for an
SqlConnection connection string?

I need to be able to allow my users to build connection
strings for Sql Server ADO.NET provider using the Data
Link Properties dialog, like the IDE does when you
select "New Connection..." in the
SqlConnection.ConnectionString drop-down in Properties.

I can invoke it and retrieve an Ole DB connection string,
but need to be able to build ADO.NET connection strings
using the following code.

MSDASC.DataLinksClass oClass = new MSDASC.DataLinksClass
();
object oCon = new ADODB.ConnectionClass();

oClass.PromptEdit(ref oCon);
MessageBox.Show((oCon as
ADODB.ConnectionClass).ConnectionString);

Note: You need to add references to the following COM
libraries:

Microsoft ActiveX Data Objects 2.7 Library
Microsoft OLE DB Service Component 1.0 Type Library


Also, is it possible to force the Provider selection to
Sql Server?

Thanks

Ben Fidge
 
N

Nicole Calinoiu

Ben Fidge said:
How do you invoke the Data Link Properties dialog for an
SqlConnection connection string?

Strip out the provider portion from the OLE DB connection string that is
returned from the data links call.
Also, is it possible to force the Provider selection to
Sql Server?

Not really. However, you can do the following instead:

1. Default to the SQL Server provider by using PromptEdit to edit a
connection with the connection string "Provider=SQLOLEDB.1" instead of
PromptNew to create a new connection string. This will cause the dialog to
open on the second tab, with the SQL Server provider pre-selected.

2. Check the provider after the edit to ensure that it's the SQL Server
provider. If it's not, force the user to re-edit the connection string.

In addition, it would probably be a good idea to test the resulting
connection string (after provider section removal) by attempting to open an
actual SqlConnection to ensure that it can be used correctly.
 
B

Ben Fidge

Excellent, I'll give it a go. Thank you very much.

Ben


-----Original Message-----


Strip out the provider portion from the OLE DB connection string that is
returned from the data links call.


Not really. However, you can do the following instead:

1. Default to the SQL Server provider by using PromptEdit to edit a
connection with the connection
string "Provider=SQLOLEDB.1" instead of
 

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