<%Dim Cn,StrDSN,StrServerName,StrDBName,StrUid,StrPwd
StrServerName="(local)"
StrDBName="Show5new"
StrUid="show5net"
StrPwd="1q2w3e4r5t6y7u8i9o0p"
Set Cn = Server.CreateObject("ADODB.Connection")
StrDSN="Driver={SQL Server};Server=" & StrServerName & ";Database=" & StrDBName & ";Uid=" & StrUid & ";Pwd=" & StrPwd & ";"
Cn.Open StrDSN%>
这个是asp的代码我想把这个代码移植到.net上面 语言支持是c#请问 StrDSN="Driver={SQL Server};Server=" & StrServerName & ";Database=" & StrDBName & ";Uid=" & StrUid & ";Pwd=" & StrPwd & ";"这个句是什么意思?

解决方案 »

  1.   

    是sql server连接字符串的一种写法connStr = "Driver={SQL Server};Server127.0.0.1;Database=northwind;Uid=sa;Pwd=123456"
      

  2.   

    数据库连接字符串,指出数据库类型、数据库所在服务器、数据库名称、连接数据库使用的用户名、连接数据库使用的用户密码在.net中建立数据库的Connection对象也必须使用这样的连接字符串
      

  3.   


     StrDSN="Server=" + StrServerName + ";Database=" + StrDBName + ";Uid=" + StrUid + ";Pwd=" + StrPwd + ";"
      

  4.   

    connectionString = "uid=show5net;server=.;database=Show5new;pwd=1q2w3e4r5t6y7u8i9o0p;connect timeout=30;"
      

  5.   

    换成C#:<%
    string StrServerName="(local)";
    string StrDBName="Show5new";
    string StrUid="show5net";
    string StrPwd="1q2w3e4r5t6y7u8i9o0p";
    string StrDSN="Driver={SQL Server};Server=" + StrServerName + ";Database=" + StrDBName + ";Uid=" + StrUid & ";Pwd=" + StrPwd + ";"SqlConnection Cn = new SqlConnection( StrDSN );
    Cn.Open();
    %>注意页面上要 <@import namespace=System.Data.SqlClient %>