2016-12-01 4 views
1

enter image description hereのMicrosoft Visual StudioのSQLサーバー接続 - 無効なポインタ

だから、私には、Microsoft SQL Management StudioでSQLデータベースを作成し、MicrosoftのVisual Studioに接続します。私はデータベースをVisual Studioにリンクしていました。今、私はWindowsフォームアプリケーション上のボタンを使ってその接続をテストするためにその接続を開きたいと思います。試してみるたびに、 "無効なポインタ"と表示されますが、データベース名は正しいです。私は何が間違っているのか分からない。

あなたは

string connectionString = 
     "data source=.\SQLEXPRESS;initial catalog=student;integrated security=True;"; 


    using (SqlConnection connection = 
     new SqlConnection(connectionString)) 
{ 
connection.Open(); 
MessageBox.Show("You are connected"); 
} 

などの適切な接続文字列を提供必要がある私はまだ私のインスタンス名がデスクトップBJSAO6Bです...無効なポインタのエラーが出るが、それは動作するようですdoes notの...

+0

SqlConnectionオブジェクトでCONN =新しいSqlConnectionオブジェクトを()を使用しますが、データベース名だけでなく、接続文字列も指定する必要があります。 – Vikram

答えて

2

SQLEXPRESS - MSSQLインスタンスの名前を指定します(異なる場合があります)。より多くのあなたは例のためにhere

1

を見ることができます:

string connectionString = "Data Source=Server-Name; Initial Catalog= Database-Name;Integrated Security=True"; //If you are using a local Database. 

SqlConnection conn = new SqlConnection(connectionString); 
conn.Open(); 
MessageBox.Show("You are connected"); 
関連する問題