3

這是我使用ASP.net的第一個項目,我努力讓我的數據庫連接正常工作。 現在,我的應用程序數據庫正在運行,我可以使用該網站進行簡單的CRUD操作。 但是,當我嘗試通過網站管理工具添加Authorizarion和身份驗證時,我得到以下異常: 無法打開用戶默認數據庫。登錄失敗。用戶'PcName \ UserName'登錄失敗。ASP.net:由於數據庫錯誤而無法使用網站管理工具

我試圖通過使用不同的連接字符串解決此問題,但沒有運氣。他們只會破壞我的網站功能。

我的連接字符串是:

<connectionStrings> 
    <add name="ProjectEntities" 
    connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI; 
         database=ProjectDB; 
         AttachDBFilename=|DataDirectory|aspnetdb.mdf; 
         User Instance=true" 
    providerName="System.Data.SqlClient" /> 
</connectionStrings> 

我使用Visual Studio 2010中,與ASP.net MVC 3和實體框架。

我真的沒有在這裏的選擇,有太多關於SQL Server Express和ASP.net的信息,我只是找不到任何工作的解決方案。

編輯:

我嘗試了幾種不同的連接字符串如下建議,並在網上找到。嘗試加載網站管理工具時,我現在遇到了不同的錯誤:找不到存儲過程'dbo.aspnet_CheckSchemaVersion'。

當谷歌搜索,我發現一些解決方案來解決這個問題。其中之一是用一些選項運行aspnet_regsql.exe。當我這樣做時,我收到以下錯誤消息:

An error has occurred. Details of the exception: 
A network-related or instance-specific error occurred while establishing a conne 
ction to SQL Server. The server was not found or was not accessible. Verify that 
the instance name is correct and that SQL Server is configured to allow remote 
connections. (provider: Named Pipes Provider, error: 40 - Could not open a conne 
ction to SQL Server) 

Unable to connect to SQL Server database. 

不知何故,似乎SQL服務器沒有運行,或什麼。我對這個問題的知識確實不足以解決這個問題。

編輯2:

我已經做了一些調查研究,只是試圖運行一個新創建的MVC 3 Internet應用程序的網站管理工具。當進入安全選項卡時,它會給我一個不同的錯誤:無法加載類型'MvcApplication1.MvcApplication'。

所以我的猜測是,我失去了在Web.config文件在我最初的項目的一些配置(如空項目創建),但不知何故,有一個新的問題......

+0

新的信息 – 2012-02-09 11:28:15

回答

3

可以嘗試不指定數據庫參數?

<connectionStrings> 
    <add name="ProjectEntities" 
     connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI; 
        AttachDBFilename=|DataDirectory|aspnetdb.mdf; 
        User Instance=true" 
     providerName="System.Data.SqlClient" /> 
</connectionStrings> 

它是否創建.mdf文件?你在網絡驅動器上工作嗎?

+0

編輯我想試試。我在我的機器上運行一切(Win 7)。 – 2012-02-09 08:59:31

+0

您的連接字符串適用於應用程序數據庫,但是當我想使用網站管理工具時,出現以下錯誤:**無法找到存儲過程'dbo.aspnet_CheckSchemaVersion'。** – 2012-02-09 10:29:00

+0

我之前有過這個錯誤,並且我找到了一些解決方案([link](http://www.compdigitec.com/labs/2010/07/13/solving-could-not-find-stored-procedure-dbo- aspnet_checkschemaversion-in-asp-net-membership /)),但它們都不適合我。我試圖運行aspnet_regsql.exe,但它失敗了,並有例外。 – 2012-02-09 10:31:06

0

連接字符串應該是:

<connectionStrings> 
<add name="ApplicationServices" connectionString="data Source=.\SQLEXPRESS; Initial Catalog=aspnetdb; Persist Security Info=True; Integrated Security=SSPI;" providerName="System.Data.SqlClient" /> 
</connectionStrings> 
相關問題