首页 新闻 会员 周边 捐助

II7 部署MVC4问题

0
悬赏园豆:20 [已关闭问题] 关闭于 2013-08-15 12:16

鄙人技术不精 问题解决不过来了

求问iis7怎么配置本地数据库的连接

现字符串:<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-VM-20130530170254;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-VM-20130530170254.mdf" providerName="System.Data.SqlClient" />

VS2012调试无任何问题 但部署到iis7上就不行了

 

在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误。未找到或无法访问服务器。请验证实例名称是否正确并且 SQL Server 已配置为允许远程连接。 (provider: SQL Network Interfaces, error: 50 - 发生了本地数据库运行时错误。无法创建自动实例。有关错误详细信息,请参阅 Windows 应用程序事件日志。
)

说明: 执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 

异常详细信息: System.Data.SqlClient.SqlException: 在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误。未找到或无法访问服务器。请验证实例名称是否正确并且 SQL Server 已配置为允许远程连接。 (provider: SQL Network Interfaces, error: 50 - 发生了本地数据库运行时错误。无法创建自动实例。有关错误详细信息,请参阅 Windows 应用程序事件日志。
)

源错误: 

行 32:                     using (var context = new UsersContext())
行 33:                     {
行 34:                         if (!context.Database.Exists())
行 35:                         {
行 36:                             // 创建不包含 Entity Framework 迁移架构的 SimpleMembership 数据库


源文件: e:\workspace\物联网生码平台维护系统\VM\Filters\InitializeSimpleMembershipAttribute.cs    行: 34 

堆栈跟踪: 

[SqlException (0x80131904): 在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误。未找到或无法访问服务器。请验证实例名称是否正确并且 SQL Server 已配置为允许远程连接。 (provider: SQL Network Interfaces, error: 50 - 发生了本地数据库运行时错误。无法创建自动实例。有关错误详细信息,请参阅 Windows 应用程序事件日志。
)]
   System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +5295167
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +242
   System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, Boolean withFailover) +5307115
   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) +920
   System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance) +307
   System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions) +434
   System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) +225
   System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) +37
   System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnectionOptions userOptions) +558
   System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnectionOptions userOptions) +67
   System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) +1052
   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& connection) +167
   System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +143
   System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) +83
   System.Data.SqlClient.SqlConnection.Open() +96
   System.Data.SqlClient.SqlProviderServices.UsingConnection(SqlConnection sqlConnection, Action`1 act) +79
   System.Data.SqlClient.SqlProviderServices.UsingMasterConnection(SqlConnection sqlConnection, Action`1 act) +384
   System.Data.SqlClient.SqlProviderServices.GetDbProviderManifestToken(DbConnection connection) +241
   System.Data.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection) +26

[ProviderIncompatibleException: 提供程序未返回 ProviderManifestToken 字符串。]
   System.Data.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection) +170
   System.Data.Entity.ModelConfiguration.Utilities.DbProviderServicesExtensions.GetProviderManifestTokenChecked(DbProviderServices providerServices, DbConnection connection) +32

[ProviderIncompatibleException: 从数据库中获取提供程序信息时出错。这可能是 Entity Framework 使用的连接字符串不正确导致的。有关详细信息,请查看内部异常并确保连接字符串正确。]
   System.Data.Entity.ModelConfiguration.Utilities.DbProviderServicesExtensions.GetProviderManifestTokenChecked(DbProviderServices providerServices, DbConnection connection) +192
   System.Data.Entity.ModelConfiguration.Utilities.DbConnectionExtensions.GetProviderInfo(DbConnection connection, DbProviderManifest& providerManifest) +39
   System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection) +46
   System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext) +62
   System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input) +123
   System.Data.Entity.Internal.LazyInternalContext.InitializeContext() +461
   System.Data.Entity.Internal.InternalContext.CreateObjectContextForDdlOps() +17
   System.Data.Entity.Database.Exists() +36
   VM.Filters.SimpleMembershipInitializer..ctor() in e:\workspace\物联网生码平台维护系统\VM\Filters\InitializeSimpleMembershipAttribute.cs:34

[InvalidOperationException: 无法初始化 ASP.NET Simple Membership 数据库。有关详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkId=256588]
   VM.Filters.SimpleMembershipInitializer..ctor() in e:\workspace\物联网生码平台维护系统\VM\Filters\InitializeSimpleMembershipAttribute.cs:45

[TargetInvocationException: 调用的目标发生了异常。]
   System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0
   System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +113
   System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +232
   System.Activator.CreateInstance(Type type, Boolean nonPublic) +83
   System.Activator.CreateInstance(Type type) +6
   System.Threading.LazyHelpers`1.ActivatorFactorySelector() +68
   System.Threading.LazyInitializer.EnsureInitializedCore(T& target, Boolean& initialized, Object& syncLock, Func`1 valueFactory) +115
   System.Threading.LazyInitializer.EnsureInitialized(T& target, Boolean& initialized, Object& syncLock) +106
   VM.Filters.InitializeSimpleMembershipAttribute.OnActionExecuting(ActionExecutingContext filterContext) in e:\workspace\物联网生码平台维护系统\VM\Filters\InitializeSimpleMembershipAttribute.cs:21
   System.Web.Mvc.Async.AsyncControllerActionInvoker.InvokeActionMethodFilterAsynchronously(IActionFilter filter, ActionExecutingContext preContext, Func`1 nextInChain) +69
   System.Web.Mvc.Async.<>c__DisplayClass3b.<BeginInvokeActionMethodWithFilters>b__35() +21
   System.Web.Mvc.Async.AsyncControllerActionInvoker.InvokeActionMethodFilterAsynchronously(IActionFilter filter, ActionExecutingContext preContext, Func`1 nextInChain) +489
   System.Web.Mvc.Async.<>c__DisplayClass3b.<BeginInvokeActionMethodWithFilters>b__35() +21
   System.Web.Mvc.Async.<>c__DisplayClass37.<BeginInvokeActionMethodWithFilters>b__31(AsyncCallback asyncCallback, Object asyncState) +191
   System.Web.Mvc.Async.WrappedAsyncResult`1.Begin(AsyncCallback callback, Object state, Int32 timeout) +130
   System.Web.Mvc.Async.AsyncControllerActionInvoker.BeginInvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters, AsyncCallback callback, Object state) +197
   System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__1e(AsyncCallback asyncCallback, Object asyncState) +446
   System.Web.Mvc.Async.WrappedAsyncResult`1.Begin(AsyncCallback callback, Object state, Int32 timeout) +130
   System.Web.Mvc.Async.AsyncControllerActionInvoker.BeginInvokeAction(ControllerContext controllerContext, String actionName, AsyncCallback callback, Object state) +302
   System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__17(AsyncCallback asyncCallback, Object asyncState) +30
   System.Web.Mvc.Async.WrappedAsyncResult`1.Begin(AsyncCallback callback, Object state, Int32 timeout) +130
   System.Web.Mvc.Controller.BeginExecuteCore(AsyncCallback callback, Object state) +382
   System.Web.Mvc.Async.WrappedAsyncResult`1.Begin(AsyncCallback callback, Object state, Int32 timeout) +130
   System.Web.Mvc.Controller.BeginExecute(RequestContext requestContext, AsyncCallback callback, Object state) +317
   System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.BeginExecute(RequestContext requestContext, AsyncCallback callback, Object state) +15
   System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__2(AsyncCallback asyncCallback, Object asyncState) +71
   System.Web.Mvc.Async.WrappedAsyncResult`1.Begin(AsyncCallback callback, Object state, Int32 timeout) +130
   System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +249
   System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) +50
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +16
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +301
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

这种错误的解决方案   在VS调试时没有任何问题,但是在II7上部署时发生问题 求大神解答

KEKI的主页 KEKI | 初学一级 | 园豆:185
提问于:2013-06-27 10:13
< >
分享
所有回答(7)
0

建议检查一下部署环境的数据库连接字符串是否正确

dudu | 园豆:29642 (高人七级) | 2013-06-27 10:24

 <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-VM-20130530170254;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-VM-20130530170254.mdf" providerName="System.Data.SqlClient" />

这个是App_data里的数据库的连接

 

LocalSqlServer

data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true

这个是iis自动生成的貌似 我不记得我有过这个数据库

支持(0) 反对(0) KEKI | 园豆:185 (初学一级) | 2013-06-27 10:43

@KEKI: IIS不会自动生成连接字符串,建议检查一下web.config中的连接字符串

支持(0) 反对(0) dudu | 园豆:29642 (高人七级) | 2013-06-27 10:52

@dudu: <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-VM-20130530170254;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-VM-20130530170254.mdf" providerName="System.Data.SqlClient" />

那应该就是这个 我VS2012调试的时候没有问题额

支持(0) 反对(0) KEKI | 园豆:185 (初学一级) | 2013-06-27 11:11
0

首先要确认你部署的那台机器上是否有安装sql server,并且安装的是什么版本,再来确定连接字符串怎么写

tubo | 园豆:264 (菜鸟二级) | 2013-06-27 22:27
0

自己已解决

KEKI | 园豆:185 (初学一级) | 2013-08-15 12:15

遇到相同的问题,希望楼主指导一下,不甚感激。

支持(0) 反对(0) sunleaf | 园豆:200 (初学一级) | 2013-08-28 14:35

我也遇到相同的问题,能请楼主指导一下么?

支持(0) 反对(0) 拂想 | 园豆:200 (初学一级) | 2013-11-05 17:40
0

我遇到了相同的问题,希望楼主帮忙解决,直接是运行时报错,软件vs2013+sqlserver2008

xiaojun军 | 园豆:202 (菜鸟二级) | 2013-11-07 13:27

你的肯定是连接字符串问题- -我的那个问题是iis上的问题 跟你这个不太一样

支持(0) 反对(0) KEKI | 园豆:185 (初学一级) | 2013-11-07 13:29

@KEKI: 奥。。  现在我的没有问题了 ,但是部署到IIS 也报错 跟你的一个样,你怎么解决的呀

支持(0) 反对(0) xiaojun军 | 园豆:202 (菜鸟二级) | 2013-11-08 13:32

我刚学Mv4,  也是到了这里出了问题,请问是怎么解决的啊?我也是vs2013+sql2008

支持(0) 反对(0) albertwmm | 园豆:200 (初学一级) | 2015-03-16 15:34
0

我也遇到发布问题,编译调试没问题,发布到IIS7就遇到如下错误:

从数据库中获取提供程序信息时出错。这可能是 Entity Framework 使用的连接字符串不正确导致的

在同一台电脑中 发布,肯定是web.config配置问题,但就是找不什么原因:

数据库连接如下

 <add name="EFDbContext" connectionString="Data Source=VBN20VETOJZ9AVB;Initial Catalog=HNTravelDB1211;Integrated Security=True;User ID=sa;Password=sa;Pooling=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />

liangsx | 园豆:202 (菜鸟二级) | 2013-12-10 12:11
0

我自己也遇到同样的问题。我是这么处理的:新创建一个空数据库,同时将connectionString改成这个数据库的连接字符串。

系统运行时会自动找到这个库,首次运行会创建没有的表.

这样就可以了。

这个问题的原因我想应该是因为你发布的机器不支持这种方式的连接字符串,没有对应的驱动造成的.

Tim Lee | 园豆:350 (菜鸟二级) | 2014-06-06 15:54
0

在这里回答一下,将应用程序池的高级选项里设置标示为system能解决这个问题。

为森 | 园豆:579 (小虾三级) | 2015-03-23 02:17
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册