SQL Server 2008 Express Edition을 백엔드로 사용하는 Winforms 응용 프로그램을 개발 중입니다.C#을 사용하여 SQL Server 2008 Express 데이터베이스에 연결
Additional information: An attempt to attach an auto-named database for file D:\Hardik\Hardik\dotnet\TestApplication\TestApplication\bin\Debug\MyDatabase.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
내 코드는 다음과 같습니다 :하지만 오류가 무엇입니까
private void Form1_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnection"].ConnectionString);
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "Select * From MyTable";
cmd.CommandType = CommandType.Text;
da = new SqlDataAdapter();
da.SelectCommand = cmd;
dt = new DataTable();
ds = new DataSet();
da.Fill(ds, "Login");
dt = ds.Tables[0];
dataGridView1.DataSource = dt;
}
내 app.config
파일은 다음과 같습니다
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="MyConnection"
connectionString="Server=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\MyDatabase.mdf;Integrated Security=True; User Instance=True"
providerName="System.Data.Client"/>
</connectionStrings>
</configuration>
?
'. AttachDbFilename' - LocalDB 대신에 사용됩니다. SQL Express의 경우 데이터베이스는 일반적으로 연결되어 있으며 응용 프로그램이 끝나면 분리되지 않습니다. –