2011-12-06 29 views
1

Windows認証ユーザー名とパスワードを使用してログインするSQL Serverに接続しようとしています。私が使用している場合しかし、それ以下のコードでは、その情報を使用すると、接続文字列にユーザー名とパスワードを指定するときは、SQL Server認証を使用しているSQL Server 2008 R2 VB.net接続

Dim connetionString As String 
    Dim cnn As SqlConnection 
    connetionString = "Data Source=MSSQLPROD;Initial Catalog=MS435_PROD;User ID=me.here;Password=mypassword;" 
    cnn = New SqlConnection(connetionString) 

    Try 
     cnn.Open() 
     MsgBox("Connection Open ! ") 
     cnn.Close() 
    Catch ex As Exception 
     MsgBox("Can not open connection ! ") 
    End Try 
+0

接続文字列に関する質問に非常に役立ちます:[connectionstrings.com](http://connectionstrings.com) –

答えて

3

...それは接続できないことを私に伝えます。ユーザー名とパスワードを削除して、次のコードを追加してください:

Data Source=MSSQLPROD;Initial Catalog=MS435_PROD;Integrated Security=SSPI 

これにより、コードを実行するコンテキストのWindows認証が使用されます。

+0

素晴らしいです。ありがとうブライアン:o) – StealthRT

関連する問題