Pergunta

I have an MSDE installed and I have a DB for it. And on a client computer an ODBC alias (x). I want to connect to this using a .NET4 program written in C#. What connection string should I use if I have only a login name (y) and a password (z)?

Or am I to extract server and database name from the registry?

Foi útil?

Solução

Try this:

Provider=MSDASQL.1;Data Source=x

where x is your ODBC alias. You will need to add security information to this, as per normal.

Outras dicas

http://support.microsoft.com/kb/310988

The example #4 is for the DSN use.

 {
   OdbcConnection cn;
   OdbcCommand cmd;
   string MyString;

   MyString="Select * from Customers";

   cn= new OdbcConnection("dsn=myDSN;UID=myUid;PWD=myPwd;");

   cmd=new OdbcCommand(MyString,cn);

   cn.Open();
   MessageBox.Show("Connected");

   cn.Close();
 }     
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top