MVC 4 连接字符串到 SQL Server 2012 [英] MVC 4 Connectionstring to SQL Server 2012

查看:38
本文介绍了MVC 4 连接字符串到 SQL Server 2012的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Visual Studio 2012 在 C# 中创建了一个全新的 MVC 4 应用程序.我正在尝试连接到一个全新的 SQL Server 2012(标准)实例,但我似乎无法正确设置我的连接字符串.

I've created a brand new MVC 4 application in C# using Visual Studio 2012. I'm trying to connect to a brand new SQL Server 2012 (Standard) instance but I can't seem to get my connection string set correctly.

来自我的 Web.config 的连接字符串:

My connection string from my Web.config:

  <connectionStrings>
    <add name="ConnectionStringName"
        providerName="System.Data.SqlClient"
        connectionString="Data Source=MyServerName;
                          Initial Catalog=MyDatabaseName;
                          Integrated Security=False;
                          User ID=MyUserID;Password=MyPassword;
                          MultipleActiveResultSets=True" />
  </connectionStrings>

每次我从 Visual Studio 中转到 ASP.NET 配置时,页面都会加载,但是一旦我单击安全",我就会收到以下消息:

Every time I go to ASP.NET Configuration from within Visual Studio, the page loads, but as soon as I click "Security" I get the following message:

您选择的数据存储有问题.这可能导致由无效的服务器名称或凭据,或不足允许.也可能是由于角色管理器功能不被启用.单击下面的按钮重定向到一个页面您可以选择一个新的数据存储.

There is a problem with your selected data store. This can be caused by an invalid server name or credentials, or by insufficient permission. It can also be caused by the role manager feature not being enabled. Click the button below to be redirected to a page where you can choose a new data store.

以下消息可能有助于诊断问题:无法连接到 SQL Server 数据库.

The following message may help in diagnosing the problem: Unable to connect to SQL Server database.

我已验证我的凭据正确(我可以使用它们通过 SQL Management Studio 进行连接).还有什么我可以检查的吗?我被难住了.

I've verified that my credentials are correct (I can use them to connect via SQL Management Studio). Is there anything else I can check? I'm stumped.

更新:

我无法从 SQL Management Studio (MSSQLSERVER) 中连接到我的默认实例,因此我重新安装了 SQL,创建了一个命名实例 (LHSQLSERVER).现在我可以在 SQL Management Studio 中连接到该实例,但我仍然从 ASP.NET 配置中收到相同的错误.

I wasn't able to connect to my default instance from within SQL Management Studio (MSSQLSERVER) so I reinstalled SQL, creating a named instance (LHSQLSERVER). Now I'm able to connect to that instance in SQL Management Studio, but I'm still getting the same error from the ASP.NET Configuration.

另一件需要注意的事情 - 我运行的 aspnet_regsql 工具来自 Framework64v4.0.30319 文件夹.如果我使用 .NET 4.5,那是否正确?

Another thing to note - the aspnet_regsql tool I ran was from the Framework64v4.0.30319 folder. Is that correct if I am using .NET 4.5?

更新 2:

我已尝试将我的连接字符串替换为我知道有效的远程站点(即 mysite.winhost.com)的连接字符串,但我仍然在 ASP.NET 网站配置工具中遇到相同的错误?FWIW 我也在使用 Windows 8,但我认为这无关紧要.

I've tried replacing my connection string with a connection string to a remote site (i.e. mysite.winhost.com) that I know works, but I'm still getting the same error in the ASP.NET Website Configuration Tool? FWIW I'm also using Windows 8, but I didn't think that would matter.

还有什么我可以检查的吗?

Any thing else I can check?

更新 3:

我发现这篇文章说你不需要aspnet_regsqlMVC 4 的工具,所以我重新运行该工具删除所有设置,但同样,没有运气.以前有人用 MVC 4 做过这个吗?

I found this post that says you don't need the aspnet_regsql tool anymore for MVC 4, so I re-ran the tool removing all the settings, but again, no luck. Has anyone done this with MVC 4 before?

更新 4:

有关我找到的解决方案,请参阅下面的答案.

See my answer below for the solution I found.

推荐答案

感谢大家的投入,我终于找到了解决方案.我看到了这篇文章 描述了 VS 2012 用于 MVC 4 的新 Simple Membership.我基本上是从头开始,创建一个新数据库、新 MVC 4 项目,然后只是按照文章中的说明进行操作.果然,只要在网页上注册"就在我的数据库中创建了表并存储了用户信息.

Thanks everyone for the input, I have finally found a solution. I came across this article that describes the new Simple Membership that VS 2012 uses for MVC 4. I basically just started over, creating a new database, new MVC 4 project, and just followed the instructions in the article. Sure enough, just "registering" on the web page created the table(s) in my database and stored the user information.

这篇关于MVC 4 连接字符串到 SQL Server 2012的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆