次の接続文字列を使用して、サービス ベースのデータベースにアクセスしています
static string appath = Library_Records.Program.app_path;
string connectionstring = @"Data Source=.\SQLEXPRESS;AttachDbFilename=appath;Integrated Security = true;User Instance = True";
connection = new SqlConnection(connectionstring);
static string dbfiles = null;
internal static string app_path
{
get { return dbfiles = "|Datadirectory|\\5700.mdf"; }
}
Library_Records:namespace、Program は含むクラス名です。Main()
を呼び出すとconnection.Open()
、次のエラーが発生します
ファイル apath の自動命名データベースをアタッチしようとして失敗しました。同じ名前のデータベースが存在するか、指定されたファイルを開くことができないか、ファイルが UNC 共有にあります。
5700
.mdf
拡張子を持つ私のデータベースです。この問題を修正するにはどうすればよいですか?