close


引用sqlClient後,以下是用VB.net連SQL Server的語法...

請問哪裡有問題?
為何出現"無法開啟登入者所要求的資料庫,登入失敗"的錯誤訊息?

============================================

Imports System.Data.SqlClient

CN = "User ID=" & UID & ";Password=" & PWD & ";Initial Catalog=" & DB_Name & ";Data Source=" & "10.0.200.85" & ";Connect Timeout=30"

Using SQL_cn As New SqlConnection(CN)
Try
SQL_cn.Open()
Using SQL_da As New SqlDataAdapter()
SQL_da.Fill(SQL_ds)
DataGridView2.DataSource = SQL_ds.Tables(0)
SQL_da.Dispose()
End Using
SQL_cn.Close()
SQL_cn.Dispose()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Using

============================================








er">


您的連結字串好像有問題


CN = "User ID=" & UID & ";Password=" & PWD & ";Initial Catalog=" & DB_Name & ";Data Source=" & "10.0.200.85" & ";Connect Timeout=30"

應該寫成


CN = "User ID=" & UID & ";Password=" & PWD & ";Initial Catalog=" & DB_Name & ";Data Source=你的IP位址;Connect Timeout=30"



另外,上面的寫法是 "正式版" SQL Server
如果是Express版,請寫成

CN = "User ID=" & UID & ";Password=" & PWD & ";Initial Catalog=" & DB_Name & ";Data Source=你的IP位址\SqlExpress;Connect Timeout=30"

再來,您安裝SQL資料庫時,選用「SQL帳號」嗎?
如果您選「Windows帳號」卻輸入帳號與密碼,可能會出錯