0
連接總是超時,即使它在trycatch內也不會生成錯誤消息。我懷疑連接字符串有問題。這是我目前有:使用SqlDataReader連接到本地.mdb文件的正確方法?
string path = @"C:\PATH\TO\wantedDB.mdb";
if (!File.Exists(path))
throw new FileNotFoundException("File not found.");
else
Console.WriteLine("File found."); // File is found, so nothing wrong with that.
string connectionstring = "Database=wantedDB;AttachDBFilename=" +
path + ";Server=(local)";
using (SqlConnection conn = new SqlConnection(connectionstring))
{
Console.WriteLine("Opening connection...");
conn.Open();
Console.WriteLine("Connection opened."); // Program never gets here.
我也嘗試了關係路徑的連接字符串,如:
string connectionstring = "Database=wantedDB;AttachDBFilename=\"wantedDB.mdb\";Server=(local)";
的DB是不是受密碼保護。我有MS Access安裝,這是否影響這個莫名其妙?我錯過了什麼?
有什麼問題是什麼呢?任何錯誤消息? – ChrisWue 2012-03-07 05:34:59
[SQLConnection.Open();拋出異常](http://stackoverflow.com/questions/2398628/sqlconnection-open-throwing-exception) – ChrisWue 2012-03-07 05:37:15
我編輯了問題的開始。 – hannu40k 2012-03-07 05:37:46