シンプルな Windows C# フォーム アプリケーションを作成しています。しかし、ローカル データベース ファイル (.sdf) に接続できません
私は使っています
using System.Data.SqlServerCe;
これは私のapp.configファイルです
<add name="ConnectionString1"
connectionString="Data Source=D:\Work Place_VS\Dilshan_Hardware\Dilshan_Hardware\Database\AppDB.sdf"
providerName="Microsoft.SqlServerCe.Client.3.5" />
<add name="ConnectionString2"
connectionString="Data Source=|DataDirectory|\Database\AppDB.sdf"
providerName="Microsoft.SqlServerCe.Client.3.5" />
次のコードを使用してデータベースファイルを接続しようとしています。
try
{
using (SqlCeConnection cn = new SqlCeConnection(ConfigurationManager.ConnectionStrings["ConnectionString1"].ToString()))
{
SqlCeCommand cmd = new SqlCeCommand("SELECT routeName FROM tbl_route", cn);
cn.Open();
SqlCeDataReader reader1 = cmd.ExecuteReader();
while (reader1.Read())
{
MessageBox.Show("Result :" + reader1[0]);
}
}
}
catch (Exception ex)
{
MessageBox.Show("Error :" + ex.ToString());
}
私が使用するConnectionString1かConnectionString2、connectionStringを作成しようとしている間、常にcatchブロックにジャンプします。
このコードのエラーを見つけるのを手伝ってください。