ASP.NET MVC上部署

问题描述:

我想我的ASP应用程序部署到虚拟主机4数据库连接错误,但我收到以下错误ASP.NET MVC上部署

System.ArgumentException: Invalid value for key 'attachdbfilename'. 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 

[ArgumentException: Invalid value for key 'attachdbfilename'.] 
    System.Data.SqlClient.SqlConnectionString.VerifyLocalHostAndFixup(String& host, Boolean enforceLocalHost, Boolean fixup) +907214 
    System.Data.SqlClient.SqlConnectionString..ctor(String connectionString) +4116 
    System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous) +24 
    System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(String connectionString, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions) +150 
    System.Data.SqlClient.SqlConnection.ConnectionString_Set(String value) +59 
    System.Data.SqlClient.SqlConnection.set_ConnectionString(String value) +4 
    System.Data.SqlClient.SqlConnection..ctor(String connectionString) +26 
    System.Data.Entity.Infrastructure.SqlConnectionFactory.CreateConnection(String nameOrConnectionString) +236 
    System.Data.Entity.Infrastructure.LocalDbConnectionFactory.CreateConnection(String nameOrConnectionString) +281 
    System.Data.Entity.Internal.LazyInternalConnection.Initialize() +327 
    System.Data.Entity.Internal.LazyInternalConnection.get_ProviderName() +13 
    System.Data.Entity.Internal.LazyInternalContext.InitializeContext() +332 
    System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) +18 
    System.Data.Entity.Internal.Linq.InternalSet`1.Initialize() +56 
    System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext() +15 
    System.Data.Entity.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider() +37 
    System.Linq.Queryable.OrderByDescending(IQueryable`1 source, Expression`1 keySelector) +66 
    georgi_it2.Models.ApplicationController..ctor() +302 
    georgi_it2.Controllers.HomeController..ctor() +5 

[TargetInvocationException: Exception has been thrown by the target of an invocation.] 
    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) +98 
    System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache) +241 
    System.Activator.CreateInstance(Type type, Boolean nonPublic) +69 
    System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +67 

[InvalidOperationException: An error occurred when trying to create a controller of type 'georgi_it2.Controllers.HomeController'. Make sure that the controller has a parameterless public constructor.] 
    System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +182 
    System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) +80 
    System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) +74 
    System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +218 
    System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +49 
    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() +8970436 
    System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184 

公司给我提供了连接字符串是这样的:

<add name="SiteSqlServer" connectionString="Server=(127.0.0.1);Database=DATABASENAME;uid=DBUSERNAME;pwd=DBPASSWORD;" providerName="System.Data.SqlClient" /> 

而我web.config文件中的一个是相同的。我已经创建了一个数据库,它与我的机器上的默认连接字符串很好地协作。

+0

您已为此问题添加标签MySql,但连接字符串中提供的providerName用于SQL Server。你正在使用哪个数据库? – StanK 2013-03-10 22:29:24

+0

System.Data.SqlClient – 2013-03-10 22:48:43

一个可能的原因:

使用WebSecurity类的身份验证时,我已经经历过这种错误。检查帐户控制器上使用的filters文件夹中的属性类。该类用于初始化WebSecurity类,但具有引用“DefaultConnection”的默认构造函数调用。将其更改为web.config的连接字符串部分中的连接字符串的名称(对于您的情况,“SiteSqlServer”),它可能会解决该问题。

+0

是的确有一个构造函数引用defaultconnection,我将其更改为SiteSqlServer,但仍然是相同的问题 – 2013-03-10 23:09:42

+0

您使用的是实体框架?你能发布EF连接字符串吗? – Oliver 2013-03-11 07:46:51

+0

不是这个EF连接 2013-03-11 17:10:35