Cdude said:
Hello I need to deploy an application.The application has to connect
to a database that is already attached to the DB on the machine.How
can i check what DB's are on the machine select the one i want to
connect to.
If you want to prompt the user for the database to use, two days ago I found
a solution to this problem that uses COM Interops:
http://www.codeguru.com/vb/gen/vb_database/article.php/c5139
It's a VB example, but I was able to get it working in C# with:
ConnectionClass connection = new ConnectionClass();
object connectionObject = connection;
dataLink.PromptEdit(ref connectionObject);
I have no doubt that there is a way to avoid creating that connectionObject,
but all of my attempts failed (in a similar manor):
dataLink.PromptEdit(ref connection) ... "Argument '1': cannot convert from
'ref ADODB.ConnectionClass' to 'ref object'
I guess VB does some automatic casting that I have been unable to duplicate.
I figured out that the Data Link Properties dialog can be set to "default"
values by setting connection.ConnectionString before the call to
PromptEdit().
I use:
connection.ConnectionString = "Provider=SQLOLEDB.1;Integrated
Security=SSPI;Persist Security Info=False;Data Source=.\\SQLEXPRESS";
So the default server is the 1st SQL Express instance on the user's local
machine, unless they changed the name of that instance. Now the user just
selects the database and we are good to go. If they did change the server
instance name, or need to select a different server, the dialog makes that
easy as well.
If someone knows of a pure managed code solution that does the same thing,
please share.
