I have put together a simple ASP.NET MVC 3 test web app that uses Entity Framework 4.1. My DBContext looks like this:
我已经整理了一个使用Entity Framework 4.1的简单的ASP.NET MVC 3测试Web应用程序。我的DBContext看起来像这样:
public class EFDbContext : DbContext
{
public DbSet<TestParent> TestParents { get; set; }
public DbSet<TestChild> TestChildren { get; set; }
}
So I am expecting EF will look for a connection string named EFDbContext. Here is what the web.config contains in my local environment:
所以我希望EF会寻找一个名为EFDbContext的连接字符串。以下是web.config在我的本地环境中包含的内容:
<connectionStrings>
<add name="EFDbContext"
connectionString="data source=.\SQLEXPRESS;Initial Catalog=testDB;Integrated Security=SSPI;MultipleActiveResultSets=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
I have provided neither a user name nor a password in the connection string. So to my understanding EF will use Windows Authentication for the database connect. In my local environment everything works as expected.
我在连接字符串中既未提供用户名也未提供密码。因此,据我所知,EF将使用Windows身份验证进行数据库连接。在我的本地环境中,一切都按预期工作。
Now - when I release this web app to the server at my web hoster I have to switch to SQL Server Authentication (limitation of the web hoster - fair enough). So I have adjusted my connection string to look like this:
现在 - 当我将这个Web应用程序发布到我的Web主机服务器上时,我必须切换到SQL Server身份验证(Web主机的限制 - 足够公平)。所以我调整了我的连接字符串,如下所示:
<connectionStrings>
<remove name="LocalSqlServer" />
<add name="EFDbContext"
connectionString="Data Source = localhost\SQLEXPRESS; Initial Catalog = testDB; User Id = dbUser; Password = dbPassword; Integrated Security = SSPI; MultipleActiveResultSets = True; Persist Security Info=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
That is the only change that I have consciously made. Unfortunately this doesn't work any more. The error message that is displayed indicates that the database connect is attempted using Windows Authentication and not SQL Server Authentication as I would expect (error message is in German but it lists the user which the hoster has confirmed is one of the Windows users they have created).
这是我有意识地做出的唯一改变。不幸的是,这不再适用了。显示的错误消息表明使用Windows身份验证尝试数据库连接,而不是我期望的SQL Server身份验证(错误消息是德语,但它列出了主机已确认的用户是他们创建的Windows用户之一)。
The error message also contains the database name as I have specified it in the Initial Catalog part of the connection string. This seems to me like a clear indication that the connection string named EFDbContext is indeed read and used by EF.
错误消息还包含数据库名称,因为我已在连接字符串的初始目录部分中指定它。在我看来,这似乎清楚地表明EF确实读取并使用了名为EFDbContext的连接字符串。
My problem is that I can't even find a starting point to get closer to the problem. The whole thing seems like a black box to me. Does EF attempt SQL Server Authentication and then switches to Windows Authentication as a fallback? Or do I need to change a setting in some config file to force EF over to SQL Server Authentication?
我的问题是我甚至找不到接近问题的起点。整件事对我来说似乎是一个黑盒子。 EF是否尝试SQL Server身份验证,然后切换到Windows身份验证作为后备?或者我是否需要更改某个配置文件中的设置以强制EF转到SQL Server身份验证?
I couldn't come up with any sensible way to scale my application back further. My Google searches didn't get me anywhere, and banging my head against the wall multiple times didn't deliver a solution either. So any help would be much appreciated.
我无法想出任何合理的方法来进一步扩展我的应用程序。我的谷歌搜索没有把我带到任何地方,并且多次敲打我的头撞墙也没有提供解决方案。所以任何帮助将不胜感激。
3
Why did you keep the "Integrated Security = SSPI; " in you connection string? See here for getting more info on connection strings.
为什么在连接字符串中保留“Integrated Security = SSPI;”?有关连接字符串的详细信息,请参见此处。
本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2012/05/10/e77ba901b933e19073aeb4e4fceb0ffb.html。