1

嗨!

我正在编写一个 asp.net 应用程序。我首先使用 entityframework 5 代码。我在本地开发此站点,但我使用网络服务器的数据库。当我将此站点发布到网络服务器时,我必须以这种方式添加连接字符串:

<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" />

我不明白,因为我已经删除了这个连接字符串,会怎样?我将连接字符串的名称写入主数据上下文、用户上下文和 websecurity.init。

谢谢期待

例外:

“/”应用程序中的服务器错误。

初始化字符串的格式不符合从索引 109 开始的规范。

说明:执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。

异常详细信息:System.ArgumentException:初始化字符串的格式不符合从索引 109 开始的规范。

源错误:

在执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪来识别有关异常起源和位置的信息。

堆栈跟踪:

[ArgumentException: 初始化字符串的格式不符合从索引 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(字符串连接字符串)+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键)+61
System.Data.SqlClient.SqlConnection.set_ConnectionString(字符串值)+66 System.Data.Entity.Internal.LazyInternalConnection.InitializeFromConnectionStringSetting(ConnectionStringSettings appConfigConnection)+122
System.Data.Entity.Internal.LazyInternalConnection.TryInitializeFromAppConfig(字符串名称, AppConfig 配置) +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:无法初始化 ASP.NET 简单成员资格数据库。有关详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkId=256588]
iAdmin.Web.Filters.SimpleMembershipInitializer..ctor() +251

[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 (类型类型)+6 System.Threading.LazyHelpers 1 valueFactory)+1151.ActivatorFactorySelector() +68
System.Threading.LazyInitializer.EnsureInitializedCore(T& target, Boolean& initialized, Object& syncLock, Func

System.Threading.LazyInitializer.EnsureInitialized(T& 目标,Boolean& 初始化,Object&syncLock)
+106 iAdmin.Web.Filters.InitializeSimpleMembershipAttribute.OnActionExecuting(ActionExecutingContext filterContext)+39
System.Web.Mvc.Async.AsyncControllerActionInvoker.InvokeActionMethodFilterAsynchronously(IActionFilter 过滤器,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 过滤器,ActionDescriptor actionDescriptor,IDictionary1 nextInChain) +69
System.Web.Mvc.Async.<>c__DisplayClass3b.<BeginInvokeActionMethodWithFilters>b__35() +21 System.Web.Mvc.Async.AsyncControllerActionInvoker.InvokeActionMethodFilterAsynchronously(IActionFilter filter, ActionExecutingContext preContext, Func


1.Begin(AsyncCallback callback, Object state, Int32 timeout) +130
System.Web.Mvc.Async.AsyncControllerActionInvoker.BeginInvokeActionMethodWithFilters(ControllerContext controllerContext, IList
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回调,对象状态,Int32超时)+130
System.Web.Mvc.Async.AsyncControllerActionInvoker.BeginInvokeAction(ControllerContext controllerContext,字符串actionName,AsyncCallback回调,对象状态)+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.BeginExecute(RequestContext requestContext, AsyncCallback 回调,对象状态)+317 System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.BeginExecute(RequestContext requestContext,AsyncCallback 回调,对象状态)+151.Begin(AsyncCallback callback, Object state, Int32 timeout) +130
System.Web.Mvc.Controller.BeginExecuteCore(AsyncCallback callback, Object state) +382
System.Web.Mvc.Async.WrappedAsyncResult



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 回调, 对象状态) +249
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback 回调, 对象状态) +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

4

2 回答 2

1

您的密码中是否有可能有分号?

例如,我可以通过这样做重现您的异常:

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

但是,如果我从密码中删除分号,它就可以工作。

于 2013-09-07T09:58:25.780 回答
0

您可能从更高级别的 web.config 或 machine.config 继承连接字符串。为避免这种情况,请考虑在配置部分添加一个<clear/>元素:connectionStrings

<connectionStrings>
    <clear/>
    <add name=... />
    ...

同样从您的堆栈跟踪来看,它看起来像是 SimpleMembershipProvider 正在尝试使用有问题的连接字符串。您可能希望从配置中删除 SimpleMembershipProvider,或将其配置为使用不同的连接字符串。

于 2013-09-07T10:15:56.273 回答