2010-11-16 89 views
3

我知道這是一個相當標準的問題......但無法弄清楚..SQL Server 2008中的連接字符串錯誤

所以這裏就是我想要做的:

我想連接到我的本地SQL服務器。\ SQLEXPRESS通過Windows身份驗證。我可以通過使用SQL Server Management Studio進行登錄。

我的連接字符串是這樣的:

string connStr = "Provider=SqlOleDB;Data Source=.\\SQLExpress; Initial Catalog=Sports; Integrated Security=SSPI"; 

它將引發我一個錯誤:

Cannot open database "Sports" requested by the login. The login failed. 

所以我嘗試:

string connStr = "Provider=SqlOleDB;Data Source=.\\SQLExpress; Initial Catalog=Sports; Trusted_Connection=True"; 

它給了我:

Invalid authorization specification 

然後我想:

string connStr = "Provider=SqlOleDB;Data Source=.\\SQLExpress; Initial Catalog=Sports; Integrated Security=True"; 

返回:

No error message available, result code: DB_E_ERRORSOCCURRED(0x80040E21). 

任何想法?

更新:我忘了提及,我正在使用運行sql server 2010 express的虛擬機windows 7。有沒有什麼與虛擬機?

回答

0

呦,

是否使用某些IDE?像VS2008一樣?首先,請嘗試在配置管理器中重新啓動SqlServer。

+0

是的。我使用VS Web Developer 2010 .. – sbs 2010-11-16 21:50:35

2

您是否熟悉http://www.connectionstrings.com ??

我會嘗試這樣的:

Server=.\\SQLExpress;Database=Sports;Integrated Security=SSPI 

這應該工作,我希望(無需指定供應商和所有的東西)。

+0

我嘗試了http://www.connectionstrings.com網站的大部分組合。如果我沒有添加提供者,它會給我一個錯誤,告訴我需要指定提供者。當我連接到服務器時,這個連接字符串工作正常,但是當我想連接到本地時不能正常工作。 – sbs 2010-11-16 22:07:53

+0

@johnnySun:你的設置有一些非常奇怪的事情,然後..... – 2010-11-16 22:19:07