我的數據庫佈局看起來像這樣使用的SqlConnection,卻找不到SQL數據庫
-App_Data
-Database.mdf
-Database_log.ldf
,這是我的代碼
string strConn = "Data Source=.\\SQLEXPRESS;Initial Catalog=Database;Integrated Security=True;";
SqlConnection myConn = new SqlConnection(strConn);
myConn.Open();
String strSQL = "INSERT INTO dbo.member (Id, Password, Name, Jobtitle,level,phone) VALUES ('a01', '123', 'bobo', 'Tester','1','010919')";
SqlCommand myCommand = new SqlCommand(strSQL, myConn);
myConn.Close();
,但是當我在瀏覽器中測試,將發送錯誤信息,並在此代碼停止「myConn.Open();」找不到服務器
這是怎麼回事?
你不應該somehwere指定mdf文件使用? –
忘記提及服務器,用戶和通行證。下面是一個例子:conn.ConnectionString = 「Data Source = ServerName;」 + 「Initial Catalog = DataBaseName;」 + 「用戶名=用戶名;」 + 「密碼=祕密;」; conn.Open(); –
我使用Windows驗證,似乎只有sql驗證需要身份和密碼? – user5509470