流畅的NHibernate:系统找不到指定的文件

时间:2015-03-22 08:44:54

标签: asp.net asp.net-mvc asp.net-web-api fluent-nhibernate

我正在尝试在Visual Studio 2013 Ultimate中的ASP.NET MVC WEB API中开发一个简单的应用程序。每件事似乎都是正确的,但我收到了这个错误:

  

'System.ComponentModel.Win32Exception:系统找不到该文件   指定的“

来源错误:

Line 104:        {
Line 105:            // Build the NHibernate ISessionFactory object
Line 106:            var sessionFactory = FluentNHibernate
Line 107:                .Cfg.Fluently.Configure()
Line 108:                .Database(

源文件:c:\ Users \ Amin \ Documents \ Visual Studio 2013 \ Projects \ Mvc4ServicesBook-master \ Mvc4ServicesBook-master \ src \ MVC4ServicesBook.Web.Api \ App_Start \ NinjectConfigurator.cs Line:106

堆栈追踪:

[Win32Exception (0x80004005): The system cannot find the file specified]

[SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)]
   System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +5341687
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +546
   System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, Boolean withFailover) +5353471
   System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover) +145
   System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout) +923
   System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance) +311
   System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData) +646
   System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) +278
   System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) +38
   System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) +732
   System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) +85
   System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) +1057
   System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) +78
   System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) +196
   System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +146
   System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +16
   System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry) +94
   System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) +110
   System.Data.SqlClient.SqlConnection.Open() +96
   NHibernate.Connection.DriverConnectionProvider.GetConnection() +112
   NHibernate.Tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.Prepare() +14
   NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.GetReservedWords(Dialect dialect, IConnectionHelper connectionHelper) +84
   NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.Update(ISessionFactory sessionFactory) +78
   NHibernate.Impl.SessionFactoryImpl..ctor(Configuration cfg, IMapping mapping, Settings settings, EventListeners listeners) +700
   NHibernate.Cfg.Configuration.BuildSessionFactory() +104
   FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory() +41

[FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.

]
   FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory() +61
   MVC4ServicesBook.Web.Api.App_Start.NinjectConfigurator.ConfigureNHibernate(IKernel container) in c:\Users\Amin\Documents\Visual Studio 2013\Projects\Mvc4ServicesBook-master\Mvc4ServicesBook-master\src\MVC4ServicesBook.Web.Api\App_Start\NinjectConfigurator.cs:106
   MVC4ServicesBook.Web.Api.App_Start.NinjectConfigurator.AddBindings(IKernel container) in c:\Users\Amin\Documents\Visual Studio 2013\Projects\Mvc4ServicesBook-master\Mvc4ServicesBook-master\src\MVC4ServicesBook.Web.Api\App_Start\NinjectConfigurator.cs:48
   MVC4ServicesBook.Web.Api.App_Start.NinjectConfigurator.Configure(IKernel container) in c:\Users\Amin\Documents\Visual Studio 2013\Projects\Mvc4ServicesBook-master\Mvc4ServicesBook-master\src\MVC4ServicesBook.Web.Api\App_Start\NinjectConfigurator.cs:35
   MVC4ServicesBook.Web.Api.App_Start.NinjectWebCommon.RegisterServices(IKernel kernel) in c:\Users\Amin\Documents\Visual Studio 2013\Projects\Mvc4ServicesBook-master\Mvc4ServicesBook-master\src\MVC4ServicesBook.Web.Api\App_Start\NinjectWebCommon.cs:59
   MVC4ServicesBook.Web.Api.App_Start.NinjectWebCommon.CreateKernel() in c:\Users\Amin\Documents\Visual Studio 2013\Projects\Mvc4ServicesBook-master\Mvc4ServicesBook-master\src\MVC4ServicesBook.Web.Api\App_Start\NinjectWebCommon.cs:48
   Ninject.Web.Common.Bootstrapper.Initialize(Func`1 createKernelCallback) in c:\Projects\Ninject\Ninject.Web.Common\src\Ninject.Web.Common\Bootstrapper.cs:50
   MVC4ServicesBook.Web.Api.App_Start.NinjectWebCommon.Start() in c:\Users\Amin\Documents\Visual Studio 2013\Projects\Mvc4ServicesBook-master\Mvc4ServicesBook-master\src\MVC4ServicesBook.Web.Api\App_Start\NinjectWebCommon.cs:27

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
   System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) +0
   System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) +192
   System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +155
   WebActivator.BaseActivationMethodAttribute.InvokeMethod() +78
   WebActivator.ActivationManager.RunActivationMethods() +342
   WebActivator.ActivationManager.Run() +22

[InvalidOperationException: The pre-application start initialization method Run on type WebActivator.ActivationManager threw an exception with the following error message: Exception has been thrown by the target of an invocation..]
   System.Web.Compilation.BuildManager.InvokePreStartInitMethodsCore(ICollection`1 methods, Func`1 setHostingEnvironmentCultures) +547
   System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +132
   System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +102
   System.Web.Compilation.BuildManager.ExecutePreAppStart() +153
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +521

[HttpException (0x80004005): The pre-application start initialization method Run on type WebActivator.ActivationManager threw an exception with the following error message: Exception has been thrown by the target of an invocation..]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9955652
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254

1 个答案:

答案 0 :(得分:0)

我受到post的启发。

就我而言,由于服务器

,这是错误的

<!--<add name="myConnectionString" connectionString="Trusted_Connection=True;database=Milano_Dev;server=(local);Integrated Security=True" />-->

这是正确的

<add name="myConnectionString" connectionString="Trusted_Connection=True;database=Milano_Dev;server=(local)\SQLEXPRESS;Integrated Security=True" />

基本上这取决于您的数据连接。我的代码仅基于我的情况。希望这对那些仍然有答案的人有所帮助。