将 ASP.Net-MVC 应用程序迁移到新服务器
基本上,我在 Windows 7 机器上使用 Visual Studio 2008 开发了这个 ASP.Net MVC 应用程序。它在本地计算机上运行良好,而且我可以放心地在 IIS 中托管它。然后我决定将其上传到 subversion,并在另一台 Windows Server 2008 计算机上获取它。我下载了它,将 IIS 文档根目录指向我的应用程序文件夹,然后启动它。
我可以很好地访问该网站。但是,一旦需要对 SQL 数据库执行任何操作,我就会收到以下错误:
建立与 SQL Server 的连接时发生与网络相关或特定于实例的错误。找不到服务器或无法访问服务器。验证实例名称是否正确以及 SQL Server 是否配置为允许远程连接。 (提供程序:SQL 网络接口,错误:26 - 定位指定的服务器/实例时出错)
我的 SQL 数据库的 ConnectionString 如下:
<add name="UserClaimsConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\UserClaims.mdf;Integrated Security=True;User Instance=True"
providerName="System.Data.SqlClient" />
该错误引发了有关允许远程连接的摆动,但数据库是本地的!此外,当我查看错误的 StackTrace 时,我在某个部分看到了一些奇怪的东西:
OpenIdProviderMvc.Models.ClaimRepository.ResetAutoSend(String upi) in C:\OpenIdProviderMvc\Models\ClaimRepository.cs:40
它所引用的目录恰好是我存储它的位置......在开发盒上!它存储在 Windows 2008 服务器上的不同位置。
我在迁移这个项目的过程中哪里出错了?
编辑: 这是完整的堆栈跟踪,可提供一些附加信息。
[SqlException (0x80131904):建立与 SQL Server 的连接时发生与网络相关或特定于实例的错误。找不到服务器或无法访问服务器。验证实例名称是否正确以及 SQL Server 是否配置为允许远程连接。 (提供商:SQL 网络接口,错误:26 - 定位指定的服务器/实例时出错)] System.Data.SqlClient.SqlInternalConnection.OnError(SqlException异常,布尔breakConnection)+4846887 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)+194 System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo,SqlInternalConnectionTds connHandler,布尔ignoreSniOpenTimeout,Int64 timeExpire,布尔加密,布尔trustServerCert,布尔integratedSecurity,SqlConnection owningObject)+4860189 System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo,字符串newPassword,布尔值ignoreSniOpenTimeout,Int64计时器Expire,SqlConnection owningObject)+90 System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(字符串主机,字符串newPassword,布尔重定向UserInstance,SqlConnection owningObject,SqlConnectionString connectionOptions,Int64 timeStart)+376 System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject,SqlConnectionString connectionOptions,字符串newPassword,布尔redirectedUserInstance)+221 System.Data.SqlClient.SqlInternalConnectionTds ..ctor(DbConnectionPoolIdentity标识,SqlConnectionString connectionOptions,对象providerInfo,字符串newPassword,SqlConnection owningObject,布尔redirectedUserInstance)+189 System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions选项,对象池GroupProviderInfo,DbConnectionPool池,DbConnection owningConnection)+4861315 System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection,DbConnectionPool池,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 externalConnection,DbConnectionFactory 连接工厂)+117 System.Data.SqlClient.SqlConnection.Open() +122 System.Data.Linq.SqlClient.SqlConnectionManager.UseConnection(IConnectionUser 用户)+44 System.Data.Linq.SqlClient.SqlProvider.get_IsSqlCe() +45 System.Data.Linq.SqlClient.SqlProvider.InitializeProviderMode() +20 System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(表达式查询)+57 System.Data.Linq.DataQuery
1.System.Collections.Generic.IEnumerable
2个参数)+178 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary.GetEnumerator() +35 C:\Downloads\DotNetOpenAuth-3.3.1.9337\OpenIdProviderMvc\Models\ClaimRepository.cs:40 中的 OpenIdProviderMvc.Models.ClaimRepository.ResetAutoSend(String upi) OpenIdProviderMvc.Controllers.AccountController.LogOn(字符串用户名,字符串密码,字符串returnUrl,布尔resetAttributeRelease)在C:\ Downloads \ DotNetOpenAuth-3.3.1.9337 \ OpenIdProviderMvc \ Controllers \ AccountController.cs:66 lambda_method(ExecutionScope,ControllerBase,Object[])+245 System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase控制器,Object[]参数)+17 System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContextcontrollerContext,IDictionary 2 个参数) +24 System.Web.Mvc.<>c__DisplayClassa.
1延续)+258 System.Web.Mvc.<>c__DisplayClassc.b__9() +20 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContextcontrollerContext,IListb__7() +53 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter过滤器,ActionExecutingContext preContext,Func 1个过滤器,ActionDescriptoractionDescriptor,IDictionary
2个参数)+193 System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContextcontrollerContext,字符串actionName)+382 System.Web.Mvc.Controller.ExecuteCore() +123 System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +23 System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +7 System.Web.Mvc.MvcHandler.ProcessRequest(HttpContextBase httpContext)+144 System.Web.Mvc.MvcHandler.ProcessRequest(HttpContext httpContext) +54 System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext httpContext) +7 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181 System.Web.HttpApplication.ExecuteStep(IExecutionStep 步骤,Boolean&completedSynchronously) +75
So basically, I developed this ASP.Net MVC application on a Windows 7 box with Visual Studio 2008. It works well on the local machine, and I was able to host it in IIS no worries. I then decided to upload it onto subversion, and fetch it on a different Windows Server 2008 machine. I downloaded it, had the IIS document root point to my application folder, and started it up.
I can visit the site fine. However, as soon as it needs to do anything with the SQL database I get the following error:
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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
My ConnectionString to the SQL database is as follows:
<add name="UserClaimsConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\UserClaims.mdf;Integrated Security=True;User Instance=True"
providerName="System.Data.SqlClient" />
The error throws a wobble about allowing remote connections, but the database is local! Additionally, when I look at the StackTrace of the error, I see something odd at one portion:
OpenIdProviderMvc.Models.ClaimRepository.ResetAutoSend(String upi) in C:\OpenIdProviderMvc\Models\ClaimRepository.cs:40
The directory which it is referring to happens to be where I had it stored... on the development box! It is stored in a different location on the Windows 2008 server.
Where have I gone wrong in migrating this project?
EDIT:
Here is the full stack trace to provide a bit of additional information.
[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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)]
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +4846887
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) +4860189
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) +376
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 options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +4861315
System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +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
System.Data.Linq.SqlClient.SqlConnectionManager.UseConnection(IConnectionUser user) +44
System.Data.Linq.SqlClient.SqlProvider.get_IsSqlCe() +45
System.Data.Linq.SqlClient.SqlProvider.InitializeProviderMode() +20
System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query) +57
System.Data.Linq.DataQuery1.System.Collections.Generic.IEnumerable<T>.GetEnumerator() +35
2 parameters) +178
OpenIdProviderMvc.Models.ClaimRepository.ResetAutoSend(String upi) in C:\Downloads\DotNetOpenAuth-3.3.1.9337\OpenIdProviderMvc\Models\ClaimRepository.cs:40
OpenIdProviderMvc.Controllers.AccountController.LogOn(String userName, String password, String returnUrl, Boolean resetAttributeRelease) in C:\Downloads\DotNetOpenAuth-3.3.1.9337\OpenIdProviderMvc\Controllers\AccountController.cs:66
lambda_method(ExecutionScope , ControllerBase , Object[] ) +245
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +17
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary2 parameters) +24
1 continuation) +258
System.Web.Mvc.<>c__DisplayClassa.<InvokeActionMethodWithFilters>b__7() +53
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func
System.Web.Mvc.<>c__DisplayClassc.b__9() +20
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList1 filters, ActionDescriptor actionDescriptor, IDictionary
2 parameters) +193
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +382
System.Web.Mvc.Controller.ExecuteCore() +123
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +23
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +7
System.Web.Mvc.MvcHandler.ProcessRequest(HttpContextBase httpContext) +144
System.Web.Mvc.MvcHandler.ProcessRequest(HttpContext httpContext) +54
System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext httpContext) +7
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
堆栈跟踪中的路径可能指向您的开发计算机上的某个路径,因为这是 .pdb 文件中的路径(它们是否已添加到 subversion 中?)。我认为这与连接错误无关,您可能需要单独解决这个问题。
The path in the stack trace probably points to some path on your dev machine because that is what is in the .pdb files (have they been added to subversion?). I don't think this is related to the connection error and you will probably have to sort that out separately.
如果服务器上尚未安装 SQL Server 2008 Express,则需要安装它。 ASP.NET 需要安装 SQL Server Express 以将 mdf 数据库文件附加到数据目录中。
您可以在此处下载它
You need to install SQL Server 2008 Express on the server if it is not already installed. ASP.NET needs sql server express installed to attach the mdf database file in your data directory.
You can download it here