Visual Studio 2010 には、接続しようとしているデータベースがありますが、接続しようとすると:
db.Open();
この間違いを引き起こします:
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 – Error Locating Server/Instance Specified)
このリンクが示すことを実行しようとしましたが、それでも同じ間違いが続きます。
何が起こっているかについてのアイデアはありますか?
編集:ファイアウォールはオフです。
接続文字列: MySQLProject.Properties.Settings.Default.dbConnectionString = "Data Source=|DataDirectory|\db.sdf"
サーバーが稼働しています:
EDIT2:
これは失敗するコードです:
public void FillData()
{
// 1 step. Open connection
// SqlConnection c = new SqlConnection("Data Source=" +db.Connection.DataSource);
SqlConnection c = new SqlConnection(MySQLProject.Properties.Settings.Default.dbConnectionString);
try
{
c.Open();
// 2 step. Create new DataAdapter
using (SqlDataAdapter a = new SqlDataAdapter("SELECT * FROM USER", c))
{
// 3 step. Use DataAdapter to fill table
DataTable t = new DataTable();
a.Fill(t);
// 4 step. Render data on the DataGridView
dataGridViewUsers.DataSource = t;
}
}
catch (SqlException e)
{
MessageBox.Show(e.Message);
}
}
編集 nº 1000:
わかりました、私はこの接続文字列を使用しました:
string con2 = @"Server=.\SQLExpress;AttachDbFilename=|DataDirectory|db.sdf;Database=db;Trusted_Connection=Yes;";
そして、次のように述べています。
:____(
わかりました、これ.sdf
は CE Sql ステートメント用であることがわかりました。しかし、作成できませ.mdf
ん。正確な理由はわかりません... CE Sql ステートメントに変更する必要がありますか?