2011-09-19 49 views
0

遇到麻煩進行SQL連接。這是我的代碼無法進行SQL連接

private static SqlConnection GetConnection() 
{ 
    SqlConnection con = new SqlConnection(); 
    con.ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=" + path + @"\App_Data\Database1.sdf;Integrated Security=True;User Instance=True"; 
    con.Open(); 

    return con; 
} 

,這就是我得到

Error: An attempt to attach an auto-named database for file \App_Data\Database1.sdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

而我的數據庫所在的文件夾的App_Data在所以不知道什麼是錯

+2

路徑的價值是什麼? – Mark

+0

變量「path」包含什麼? –

回答

0

這可能包括你所面臨的問題...

msdn on sql express

對不起,鏈接BU t我不想複製粘貼別人的發現...