2013-04-10 41 views
0

我剛剛用Microsoft SQL Server Management Studio創建了一個新的SQL數據庫,並試圖通過一些C#代碼連接到它。但是,我遇到了一些問題。查找數據庫地址並通過代碼連接到

我想用下面的線路連接到我的數據庫:

String DBConnection = "Data Source=unknown; Database=SQLExpress\\Darkride; Language=English"; 

但是我的程序無法找到我的數據庫,因爲我不知道在哪裏我的數據源。我一直在努力尋找它幾個小時,但我什麼都沒有。

有誰知道我在哪裏可以找到我的數據庫數據源?

+1

請您的具體問題http://meta.stackexchange.com/questions/10647/how-do-i-write-a-good更新您的標題-title – 2013-04-10 08:07:06

+0

你的問題與mysql(錯誤標記)或SQL管理問題(錯誤的標題)無關。 – 2013-04-10 08:09:28

+0

'。\ SQLEXPRESS'或'localhost \ SQLEXPRESS'或'127.0.0.1 \ SQLEXPRESS' – 2013-04-10 08:35:10

回答

1

你缺少的連接字符串中Initial Catalog:更多選擇

String DBConnection ="Data Source='localhost';Integrated Security='SSPI' Initial Catalog=Darkride;"; 

檢查here

0

添加 "Data Source=127.0.0.1; Database=SQLExpress\\Darkride;Initial Catalog=YourDataBase;User Id=user;Password=pass"

可以使用SqlConnectionStringBuilder類來建立你的連接串。

好發部位爲refenrence是http://www.connectionstrings.com/

0

有連接字符串的格式爲:

String DBConnection = "Data Source=27.0.0.1;;Initial Catalog=Darkride;User ID=userIDText;Password=PasswordText";