I am used to connecting to my database using a querystring and a connection like this:
string connectionString = "server=\'myserver\'; user id=\'myuser\'; password=\'mypw;database=\'mydb\'";
System.Data.IDbConnection dbConnection = new System.Data.SqlClient.SqlConnection(connectionString);
I write in C# and don't know how to connect to a database using a DSN. I have this VB code that's supposed to connect with DSN:
<%
set conn = Server.CreateObject("ADODB.Connection")
conn.open"DSN=MyDSN;UID=user;PWD=password;DATABASE=databasename"
%>
But I need it in C#...
I tried using a query string like this one
string connectionString="DSN=mydsn;UID=myuser;PWD=mypw;DATABASE=mydb";
and got this error :Unknown connection option in connection string: dsn. :
Any help would be greatly appreciated... thanksPlease check the following :
|||that's classic ASP code in VBScript - not ASP.NET code in VB.NET
OdbcConnection cn;
OdbcCommand cmd;
string MyString;MyString="Select * from test";
cn= new OdbcConnection("dsn=myDSN;UID=myUid;PWD=myPwd;");
cmd=new OdbcCommand(MyString,cn);
cn.Open();
......
Anyway, is there a particular reason you NEED to use a DSN? it IS possible, but it's not the best option.
No comments:
Post a Comment