2013-03-10 154 views
0

我想我的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

回答

0

一個可能的原因:

使用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