简体   繁体   English

无法使用NHibernate登录到SQL Server,但使用Management Studio或sqlcmd可以正常工作

[英]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.

相关问题 当我可以使用具有相同登录名的SQL Server Management Studio进行连接时,为什么我的应用程序不连接到SQL Server数据库? - Why won't my application connect to SQL Server database when I can connect using SQL Server Management Studio with the same login? C# - XLSX 到 SQL Server - OpenRecordSet 不适用于 C#,但适用于 MS SQL Server Management Studio - C# - XLSX to SQL Server - OpenRecordSet not working in C# but works in MS SQL Server Management Studio SQL Server 2008 datetime不会通过c#插入,但可以在SQL Server Management Studio中使用吗? - SQL Server 2008 datetime will not insert via c# but works within SQL Server Management Studio? SQL Server Management Studio中的架构 - Schema in SQL Server Management Studio SQL Server Management Studio中的复选框 - Checkbox in SQL Server Management Studio 无法通过应用程序,SQL Server Management Studio或VS Server资源管理器访问SQL Server MDF文件 - Cannot access SQL Server MDF file through app, SQL Server Management Studio, or VS Server explorer SQL查询可在SQL Server Management Studio中使用,但不适用于ASP.Net应用程序 - SQL query works in SQL Server Management Studio but not from ASP.Net application 使用SQL Server Management Studio进行数据库查询时遇到麻烦 - Having trouble with a database query using SQL Server Management Studio 在 C # .NET 中运行 SQL 查询时出现问题,即使该查询在 microsoft ZAC5C74B64B4AFFB583AZ52EF2F18 中有效 - Problem running SQL query in C # .NET even though the query works in microsoft sql server management studio SELECT在程序中超时,但在SQL Server Management Studio中有效 - SELECT times out from program but works from SQL Server Management Studio
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM