日期:2014-05-18  浏览次数:20403 次

SQL server数据连接串问题 ,怎么就不对那?大侠们帮看看
Dim   TransProConnectionDB   As   OleDbConnection
                Dim   strConnectiongString   As   String   =   "Provider=SQLOLEDB;DRIVER=SQL   Server;UID=LLL;Trusted_Connection=Yes;DATABASE=TransPro;WSID=KKK-NNN   ;APP=Microsoft   Data   Access   Components;SERVER=KKK-NNN\SQLEXPRESS "
                TransProConnectionDB   =   New   OleDbConnection(strConnectiongString)
                Dim   da   As   New   OleDbDataAdapter( "select   *   from   TransProInfo ",   TransProConnectionDB)
                Dim   dt   As   New   DataTable
                da.Fill(dt)

这段代码,在winform里正确,可在asp.net里就是连不上。提示说字符串无效?为何

头痛啊

------解决方案--------------------
SqlConnection conn=new SqlConnection(ConfigurationSettings.AppSettings[ "ConnectionString "].ToString());
SqlDataAdapter da=new SqlDataAdapter( "select * from detail ",conn);
DataSet ds=new DataSet();
try
{
da.Fill(ds, "testTable ");
this.DataGrid1.DataSource=ds.Tables[ "testTable "];
this.DataGrid1.DataBind();
}
catch(Exception ex)
{
Response.Write(ex.Message.ToString());
}
------解决方案--------------------
TransProConnectionDB = New OleDbConnection(strConnectiongString)
换成SqlConnection对象看看
------解决方案--------------------
关键是看你的连接库是什么?

SqlClient在字符串里是不要Provider和DRIVER的
OLEDB才会有
------解决方案--------------------
楼主你怎么连接字符串这么长,我一般就这么写Provider=SQLOLEDB;Server=XXXXX;database=XXXX;uid=XXX;pwd=XXX
刚刚测试了一下你代码,只把连接字符串换了一个我局域网的,没有问题。
------解决方案--------------------
在web.config文件中添加
<appSettings>
<add key= "ConnectionString " value= "data source=.;initial catalog=数据库名;user id=用户名;password= "> </add>
</appSettings>
------解决方案--------------------
LZ 的用法是没有错的,

但,

.net 中,MS 强烈建议使用 SqlClient (Microsoft .NET Data Provider For SQL Server) 链接 SQL Server 7+ ,以获取比 OleDb 更高的性能

string connStr = "SERVER=KKK-NNN\SQLEXPRESS;UID=LLL;DATABASE=TransPro; "
System.Data.SqlClient.SqlConnection conn = new SqlConnection(connStr);
// ...

------解决方案--------------------
try
Dim TransProConnectionDB As OleDbConnection
Dim strConnectiongString As String = "Provider=SQLOLEDB;DRIVER=SQL Server;UID=LLL;Trusted_Connection=Yes;DATABASE=TransPro;WSID=KKK-NNN ;APP=Microsoft Data Access Components;SERVER=KKK-NNN "
TransProConnectionDB = New OleDbConnection(strConnectiongString)
Dim da As New OleDbDataAdapter( "select * from TransProInfo ", TransProConnectionDB)
Dim dt As New DataTable
da.Fill(dt)