我可以正常连接ado.net。但是,当我尝试连接nHibernate时,我收到以下错误。
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="connection.connection_string">Server=xxxxx\SQLEXPRESS; Database=xxxxx; User ID=xxxxx; Password=xxxxx; Trusted_Connection=True</property>
<property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
<property name="show_sql">true</property>
</session-factory>
</hibernate-configuration>
建立与SQL Server的连接时发生与网络相关或特定于实例的错误。服务器未找到或无法访问。验证实例名称是否正确,以及SQL Server是否配置为允许远程连接。 (提供程序:SQL网络接口,错误:26 - 查找指定的服务器/实例时出错)
[SqlException(0x80131904):建立与SQL Server的连接时发生与网络相关或特定于实例的错误。服务器未找到或无法访问。验证实例名称是否正确,以及SQL Server是否配置为允许远程连接。 (提供程序:SQL网络接口,错误:26 - 找到指定的服务器/实例时出错)] System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception,Boolean breakConnection)+4845255 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)+194 System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo,SqlInternalConnectionTds connHandler,Boolean ignoreSniOpenTimeout,Int64 timerExpire,Boolean encrypt,Boolean trustServerCert,Boolean integratedSecurity,SqlConnection owningObject)+4858557 System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo,String newPassword,Boolean ignoreSniOpenTimeout,Int64 timerExpire,SqlConnection owningObject)+90 System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host,String newPassword,Boolean redirectedUserInstance,SqlConnection owningObject,SqlConnectionString connectionOptions,Int64 timerStart)+342 System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject,SqlConnectionString connectionOptions,String newPassword,Boolean redirectedUserInstance)+221 System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity,SqlConnectionString connectionOptions,Object providerInfo,String newPassword,SqlConnection owningObject,Boolean redirectedUserInstance)+189 System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions选项,Object poolGroupProviderInfo,DbConnectionPool池,DbConnection owningConnection)+185 System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection,DbConnectionPool pool,DbConnectionOptions选项)+31 System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject)+433 System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject)+66 System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)+499 System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)+65 System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection,DbConnectionFactory connectionFactory)+117 System.Data.SqlClient.SqlConnection.Open()+ 122 NHibernate.Connection.DriverConnectionProvider.GetConnection()+ 102 NHibernate.Tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.Prepare()+15 NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.GetReservedWords(Dialect dialect,IConnectionHelper connectionHelper)+65 NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.Update(ISessionFactory sessionFactory)+80 NHibernate.Impl.SessionFactoryImpl..ctor(配置cfg,IMapping映射,设置设置,EventListeners侦听器)+599 NHibernate.Cfg.Configuration.BuildSessionFactory()+ 87 D:\ dev \ MyProject \ XXX \ XXX.Domain \ Repositories \ NHibernateHelper.cs中的XXX.Domain.Repositories.NHibernateHelper.get_SessionFactory():23 D:\ dev \ MyProject \ XXX \ XXX.Domain \ Repositories \ NHibernateHelper.cs中的XXX.Domain.Repositories.NHibernateHelper.OpenSession():31 D:\ dev \ MyProject \ XXX \ XXX.Domain \ Repositories \ EntryRepository.cs中的XXX.Domain.Repositories.EntryRepository.GetCountByGmapId(Int32 gmapId):152 D:\ dev \ MyProject \ XXX \ XXX.Controls \ Activity.ascx.cs中的XXX.Controls.Activity.BindRepeater(Int32 id):58 D:\ dev \ MyProject \ XXX \ XXX.Controls \ Activity.ascx.cs中的XXX.Controls.Activity.DropDownListMaps_SelectedIndexChanged(Object sender,EventArgs e):75 System.Web.UI.WebControls.ListControl.OnSelectedIndexChanged(EventArgs e)+111 System.Web.UI.WebControls.DropDownList.RaisePostDataChangedEvent()+134 System.Web.UI.WebControls.DropDownList.System.Web.UI.IPostBackDataHandler.RaisePostDataChangedEvent()+10 System.Web.UI.Page.RaiseChangedEvents()+ 165 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint)+1485
答案 0 :(得分:1)
来自http://www.connectionstrings.com/:
Server=myServerAddress;Database=myDataBase;
User ID=myUsername;Password=myPassword;Trusted_Connection=False;
我会尝试设置Trusted_Connection=False
,看看会发生什么。
通常当我看到该错误时,这是因为我的连接字符串不正确或数据库已关闭/无法访问,但我确定还有其他可能的原因。