2013-09-05 18 views
1

Hy!ASP.NET連接字符串不符合規範

我在寫一個asp.net應用程序。我首先使用entityframework 5代碼。我在本地開發這個網站,但是我使用了網絡服務器的數據庫。當我發佈這個網站的web服務器,我要補充的連接字符串中這樣說:

<add name="strConn" connectionString="Data Source=localhost;Initial Catalog=DBNAME;Integrated Security=false;User ID=DBUSERNAME;Password=DBPASSWORD" /> 

,而不是它:

<add name="constringtwo" connectionString="Server=plumeria.arvixe.com,1433;Database=DBNAME;User Id=DBUSERNAME;Password=DBPASSWORD;" providerName="System.Data.SqlClient" /> 

,當我嘗試打開我的網站,我得到了一個例外。 我寫信給支持我得到了這樣的回答:

你似乎試圖附加數據庫,

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

我不明白,因爲我已經刪除了這個ConnectionString的,怎麼會是誰? 我將連接字符串的名稱寫入主datacontext,usercontext和websecurity.init。

謝謝期待

例外:

Server Error in '/' Application.

Format of the initialization string does not conform to specification starting at index 109.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Format of the initialization string does not conform to specification starting at index 109.

Source Error:

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.

Stack Trace:

[ArgumentException: Format of the initialization string does not conform to specification starting at index 109.]
System.Data.Common.DbConnectionOptions.GetKeyValuePair(String connectionString, Int32 currentPosition, StringBuilder buffer, Boolean useOdbcRules, String& keyname, String& keyvalue) +5314204
System.Data.Common.DbConnectionOptions.ParseInternal(Hashtable parsetable, String connectionString, Boolean buildChain, Hashtable synonyms, Boolean firstKey) +124
System.Data.Common.DbConnectionOptions..ctor(String connectionString, Hashtable synonyms, Boolean useOdbcRules) +95
System.Data.SqlClient.SqlConnectionString..ctor(String connectionString) +59
System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous) +24
System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(DbConnectionPoolKey key, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions) +167
System.Data.SqlClient.SqlConnection.ConnectionString_Set(DbConnectionPoolKey key) +61
System.Data.SqlClient.SqlConnection.set_ConnectionString(String value) +66 System.Data.Entity.Internal.LazyInternalConnection.InitializeFromConnectionStringSetting(ConnectionStringSettings appConfigConnection) +122
System.Data.Entity.Internal.LazyInternalConnection.TryInitializeFromAppConfig(String name, AppConfig config) +32
System.Data.Entity.Internal.LazyInternalConnection.Initialize() +127
System.Data.Entity.Internal.LazyInternalConnection.get_ProviderName() +13 System.Data.Entity.Internal.LazyInternalContext.InitializeContext() +346 System.Data.Entity.Internal.InternalContext.CreateObjectContextForDdlOps() +17 System.Data.Entity.Database.Exists() +36 iAdmin.Web.Filters.SimpleMembershipInitializer..ctor() +103

[InvalidOperationException: The ASP.NET Simple Membership database could not be initialized. For more information, please see http://go.microsoft.com/fwlink/?LinkId=256588]
iAdmin.Web.Filters.SimpleMembershipInitializer..ctor() +251

[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, 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
iAdmin.Web.Filters.InitializeSimpleMembershipAttribute.OnActionExecuting(ActionExecutingContext filterContext) +39
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.b_35() +21 System.Web.Mvc.Async.<>c_DisplayClass37.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.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.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

+0

如何發佈到您的服務器,您是否在部署之前刪除文件? – meda

+0

您可能想要在服務器上發佈並手動刪除您的web.config。我注意到某些部署方法並不擅長獲取web.config/app.config文件中的更改 – Jedediah

+0

web部署在vs 12 版本中刪除目標文件中的其他文件 – user1693057

回答

1

有沒有可能是你有你的密碼分號?

例如,我可以這樣做重現您的例外:

new SqlConnection("Data Source=localhost;Initial Catalog=DBNAME;Integrated Security=false;User ID=DBUSERNAME;Password=DBPASSWOR;D;") 

但是,如果我從密碼刪除分號,它的工作原理。

0

您可能從較高級別的web.config或machine.config繼承連接字符串。爲了避免這種情況,考慮增加一個<clear/>元素的connectionStrings配置部分:

<connectionStrings> 
    <clear/> 
    <add name=... /> 
    ... 
從您的堆棧跟蹤

此外,它看起來就像是SimpleMembershipProvider的是試圖使用違規的連接字符串。您可能希望從您的配置中移除SimpleMembershipProvider,或將其配置爲使用其他連接字符串。