Im getting login failed error when trying to connect to my database using 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.
But using sqlcmd
or Management Studio it works fine (using Windows Auth)!
What could be the problem?
EDIT The NHibernate exception:
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". 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.
If you're not running under IIS, make sure your current user account (Windows) can access the database, as you're using Integrated Security.
Link on the error: 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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With