[英]Cannot login to SQL Server using NHibernate, but with Management Studio or sqlcmd it works
Im getting login failed error when trying to connect to my database using NHibernate: 我尝试使用NHibernate连接到我的数据库时出现登录失败错误:
var config = Fluently.Configure()
.Database(MsSqlConfiguration
.MsSql2005
.ConnectionString("Data Source=SERVER1\\SQLEXPRESS;Integrated Security=SSPI;Initial Catalog=xxx"))
.Mappings(x => x.FluentMappings.AddFromAssembly(Assembly.GetExecutingAssembly()));
With Error 18456 State 5
in the log viewer in SQL Management Studio. 在SQL Management Studio的日志查看器中使用Error 18456 State 5
。
But using sqlcmd
or Management Studio it works fine (using Windows Auth)! 但是使用sqlcmd
或Management Studio它可以正常工作(使用Windows Auth)!
What could be the problem? 可能是什么问题呢?
EDIT The NHibernate exception: 编辑 NHibernate异常:
Test method ProjektLogg.Tests.NHibernateTests.ShouldBeAbleToGenerateFactory threw exception:
FluentNHibernate.Cfg.FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
---> NHibernate.HibernateException: Login failed for user XXX-INTRANET\username. ---> System.Data.SqlClient.SqlException: Login failed for user XXX-INTRANET\username.
That error message means "Invalid UserID". 该错误消息表示“无效的用户ID”。 If you're running IIS, make sure your application pool uses the same identity as the user who you are connecting to the database with in management studio. 如果您正在运行IIS,请确保您的应用程序池使用与您在管理工作室中连接到数据库的用户相同的标识。
If you're not running under IIS, make sure your current user account (Windows) can access the database, as you're using Integrated Security. 如果您未在IIS下运行,请确保当前用户帐户(Windows)可以访问数据库,因为您正在使用集成安全性。
Link on the error: http://blogs.msdn.com/b/sql_protocols/archive/2006/02/21/536201.aspx 链接错误: http : //blogs.msdn.com/b/sql_protocols/archive/2006/02/21/536201.aspx
EDIT: Hang on, you're missing Initial Catalog . 编辑:坚持,你缺少初始目录 。 Try this: 试试这个:
"Data Source=SERVER1\\SQLEXPRESS;Integrated Security=SSPI;Initial Catalog=YourDatabase"
I cleaned the whole solution now it works. 我现在清理了整个解决方案。 Sorry to waste your time, guys. 伙计们,不好意思浪费你的时间。 Appreciate your answers. 感谢您的回答。
I faced a similar problem and I realized that unlike Entity Framework, (Fluent)NHibernate does not create a database for you. 我遇到了类似的问题,我意识到与实体框架不同,(流畅)NHibernate不会为您创建数据库。 The solution was to create an empty database. 解决方案是创建一个空数据库。
The following segment in your ConnectionString means that database xxx must already exist: ConnectionString中的以下段表示数据库xxx必须已存在:
Initial Catalog=xxx
我无法使用集成安全性,我必须在连接字符串中提供用户和密码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.