0

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?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Zéiksz
  • 688
  • 1
  • 11
  • 25
  • What have you tried so far. A Google search will net you MANY examples of connection strings for C#... – Brian Apr 17 '13 at 07:00
  • Have a look at www.connectionstrings.com; Maybe that will contain the one you need. – ferdyh Apr 17 '13 at 07:02
  • I would not ask here if I found a good result in google or connectionstrings.com. Yes I tried both. They got results only if I know the server name. I only got an ODBC alias. – Zéiksz Apr 17 '13 at 07:04
  • What does your connection string look like now? How was the ODBC DSN set up? Is it a user DSN, or a system DSN? – kdmurray Apr 17 '13 at 07:06
  • I tried this many ways. The current is: "Driver={SQL Server};User ID=" + y + ";Password=" + z + ";DSN=" + x. I tried "Provider", also "Server", etc. tags. No "luck" so far - that is why I ask here. – Zéiksz Apr 17 '13 at 07:10

2 Answers2

1

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();
 }     
Zéiksz
  • 688
  • 1
  • 11
  • 25
1

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.

muhmud
  • 4,474
  • 2
  • 15
  • 22