This is my first project using ASP.net and I'm struggling to get my database connection working. Right now the database for my application data is working and I can use the website to do simple CRUD operations. However, when I try to add Authorizarion and Authentication via the Web Site Administration Tool I get the following exception: Cannot open user default database. Login failed. Login failed for user 'PcName\UserName'.
这是我第一个使用ASP.net的项目,我正在努力使我的数据库连接工作。现在,我的应用程序数据的数据库正在工作,我可以使用这个网站进行简单的CRUD操作。但是,当我尝试通过Web站点管理工具添加Authorizarion和身份验证时,我遇到了以下异常:无法打开用户默认数据库。登录失败。用户“PcName\用户名”登录失败。
I have tried solving this problem by using different connection strings, but without luck. They would just break my website functionality.
我尝试过用不同的连接字符串来解决这个问题,但是没有运气。他们会破坏我的网站功能。
My connection string is:
我的连接字符串:
<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>
I'm using Visual Studio 2010, with ASP.net MVC 3 and the Entity Framework.
我使用Visual Studio 2010,使用ASP.net MVC 3和实体框架。
I'm really out of options here, there is way too much information about SQL Server Express and ASP.net and I just can't find any working solution.
我实在没有办法了,关于SQL Server Express和ASP.net的信息太多了,我找不到任何可用的解决方案。
EDIT:
编辑:
I tried several different connection strings as suggested below and found online. I now have a different error when trying to load the Web Site Administration Tool: Could not find stored procedure 'dbo.aspnet_CheckSchemaVersion'.
我尝试了几个不同的连接字符串,如下所示,并在网上找到。在尝试加载Web站点管理工具时,我现在有一个不同的错误:无法找到存储过程“dbo. aspnet_checkschemavoidance”。
When Googling that I found some solutions to fix that problem. One of those was to run aspnet_regsql.exe with some option. When doing that I get the following error message:
在谷歌上搜索时,我找到了一些解决方法。其中之一就是运行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.
Somehow it seems that the SQL server is not running, or something. My knowledge about this subject is really insufficient to fix this problem.
在某种程度上,SQL服务器似乎没有运行,或者其他什么。我对这个问题的了解不足以解决这个问题。
EDIT 2:
编辑2:
I've done some more research and just tried to run the Web Site Administration Tool of an newly created MVC 3 Internet Application. When going to the security tab it gives me a different error: Could not load type 'MvcApplication1.MvcApplication'.
我还做了一些研究,并尝试运行一个新创建的MVC 3 Internet应用程序的Web站点管理工具。当进入security选项卡时,它会给我一个不同的错误:无法加载“MvcApplication1.MvcApplication”类型。
So my guess is that I'm missing some configurations in Web.config in my initial project (created as empty project), but somehow there is a new problem...
所以我的猜测是我在网络中漏掉了一些配置。在我的初始项目中配置(创建为空项目),但是不知何故出现了一个新问题……
2 个解决方案
#1
3
Can you try without specifying database parameter?
可以尝试而不指定数据库参数吗?
<connectionStrings>
<add name="ProjectEntities"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;
AttachDBFilename=|DataDirectory|aspnetdb.mdf;
User Instance=true"
providerName="System.Data.SqlClient" />
</connectionStrings>
Does it creates the .mdf file at all? Are you working on network drive?
它是否创建了.mdf文件?你正在做网络驱动器吗?
#2
0
the connection string should be:
连接字符串应该是:
<connectionStrings>
<add name="ApplicationServices" connectionString="data Source=.\SQLEXPRESS; Initial Catalog=aspnetdb; Persist Security Info=True; Integrated Security=SSPI;" providerName="System.Data.SqlClient" />
</connectionStrings>
#1
3
Can you try without specifying database parameter?
可以尝试而不指定数据库参数吗?
<connectionStrings>
<add name="ProjectEntities"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;
AttachDBFilename=|DataDirectory|aspnetdb.mdf;
User Instance=true"
providerName="System.Data.SqlClient" />
</connectionStrings>
Does it creates the .mdf file at all? Are you working on network drive?
它是否创建了.mdf文件?你正在做网络驱动器吗?
#2
0
the connection string should be:
连接字符串应该是:
<connectionStrings>
<add name="ApplicationServices" connectionString="data Source=.\SQLEXPRESS; Initial Catalog=aspnetdb; Persist Security Info=True; Integrated Security=SSPI;" providerName="System.Data.SqlClient" />
</connectionStrings>