HY!
我正在编写一个asp.net应用程序。我首先使用entityframework 5代码。我在本地开发这个站点,但是我使用了webserver的数据库。当我将此站点发布到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" />
我不明白,因为我已经删除了这个连接字符串,它会怎么样? 我将连接字符串的名称写入主datacontext,usercontext和websecurity.init。
谢谢你期待
例外:
&#39; /&#39;中的服务器错误应用
初始化字符串的格式不符合规范 从索引109开始。
描述:执行期间发生了未处理的异常 当前的网络请求。请查看堆栈跟踪了解更多信息 有关错误的信息以及它在代码中的起源。
异常详细信息:System.ArgumentException:。的格式 初始化字符串不符合从...开始的规范 指数109。
来源错误:
执行期间生成了未处理的异常 当前的网络请求。有关的来源和位置的信息 可以使用下面的异常堆栈跟踪来识别异常。
堆栈追踪:
[ArgumentException:初始化字符串的格式没有 符合从索引109开始的规范。] System.Data.Common.DbConnectionOptions.GetKeyValuePair(字符串 connectionString,Int32 currentPosition,StringBuilder buffer,Boolean useOdbcRules,String&amp; keyname,String&amp; keyvalue)+5314204
System.Data.Common.DbConnectionOptions.ParseInternal(哈希表 parsetable,String connectionString,Boolean buildChain,Hashtable 同义词,布尔值firstKey)+124
System.Data.Common.DbConnectionOptions..ctor(String connectionString, Hashtable的同义词,Boolean useOdbcRules)+95
System.Data.SqlClient.SqlConnectionString..ctor(字符串 connectionString)+59
System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(字符串 connectionString,DbConnectionOptions上一页)+24
System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(DbConnectionPoolKey key,DbConnectionPoolGroupOptions poolOptions,DbConnectionOptions&amp; 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(字符串 name,AppConfig config)+32
System.Data.Entity.Internal.LazyInternalConnection.Initialize()+ 127 7 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&amp; canBeCached, RuntimeMethodHandleInternal&安培; ctor,布尔&amp; bNeedSecurityCheck)+0
System.RuntimeType.CreateInstanceSlow(Boolean publicOnly,Boolean skipCheckThis,Boolean fillCache,StackCrawlMark&amp; stackMark)+113
System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis,Boolean fillCache,StackCrawlMark&amp; stackMark) +232 System.Activator.CreateInstance(Type type,Boolean nonPublic)+83 System.Activator.CreateInstance(Type type)+6 System.Threading.LazyHelpers1.ActivatorFactorySelector() +68
1 valueFactory)+115
System.Threading.LazyInitializer.EnsureInitializedCore(T& target, Boolean& initialized, Object& syncLock, Func
System.Threading.LazyInitializer.EnsureInitialized(T&amp; target,Boolean&amp; 初始化,对象&amp; syncLock)+106
iAdmin.Web.Filters.InitializeSimpleMembershipAttribute.OnActionExecuting(ActionExecutingContext filterContext)+39
System.Web.Mvc.Async.AsyncControllerActionInvoker.InvokeActionMethodFilterAsynchronously(IActionFilter filter,ActionExecutingContext preContext,Func1 nextInChain) +69
1 nextInChain)+489
System.Web.Mvc.Async.<>c__DisplayClass3b.<BeginInvokeActionMethodWithFilters>b__35() +21 System.Web.Mvc.Async.AsyncControllerActionInvoker.InvokeActionMethodFilterAsynchronously(IActionFilter filter, ActionExecutingContext preContext, Func
System.Web.Mvc.Async&LT;&GT; C_ DisplayClass3b.b _35() +21 System.Web.Mvc.Async。&lt;&gt; c_ DisplayClass37.b _31(AsyncCallback asyncCallback,Object asyncState)+191
System.Web.Mvc.Async.WrappedAsyncResult1.Begin(AsyncCallback callback, Object state, Int32 timeout) +130
1个过滤器,ActionDescriptor actionDescriptor, IDictionary的
System.Web.Mvc.Async.AsyncControllerActionInvoker.BeginInvokeActionMethodWithFilters(ControllerContext controllerContext, IList2 parameters, AsyncCallback callback, Object state) +197
1.Begin(的AsyncCallback 回调,对象状态,Int32超时)+130
System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__1e(AsyncCallback asyncCallback, Object asyncState) +446
System.Web.Mvc.Async.WrappedAsyncResult
System.Web.Mvc.Async.AsyncControllerActionInvoker.BeginInvokeAction(ControllerContext controllerContext,String actionName,AsyncCallback callback,Object 国家)+302
System.Web.Mvc&LT;&GT; C_ DisplayClass1d.b _17(的AsyncCallback asyncCallback,Object asyncState)+30
System.Web.Mvc.Async.WrappedAsyncResult1.Begin(AsyncCallback callback, Object state, Int32 timeout) +130
1.Begin(的AsyncCallback 回调,对象状态,Int32超时)+130
System.Web.Mvc.Controller.BeginExecuteCore(AsyncCallback callback, Object state) +382
System.Web.Mvc.Async.WrappedAsyncResult
System.Web.Mvc.Controller.BeginExecute(RequestContext requestContext, AsyncCallback回调,对象状态)+317
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.BeginExecute(的RequestContext requestContext,AsyncCallback回调,对象状态)+15
System.Web.Mvc&LT;&GT; C_ DisplayClass8.b _2(的AsyncCallback asyncCallback,Object asyncState)+71
System.Web.Mvc.Async.WrappedAsyncResult`1.Begin(AsyncCallback的 回调,对象状态,Int32超时)+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&amp; completedSynchronously)+155
答案 0 :(得分:1)
您的密码中是否有分号?
例如,我可以通过这样做来重现您的异常:
new SqlConnection("Data Source=localhost;Initial Catalog=DBNAME;Integrated Security=false;User ID=DBUSERNAME;Password=DBPASSWOR;D;")
但是,如果我从密码中删除分号,它就会起作用。
答案 1 :(得分:0)
您可能从更高级别的web.config或machine.config继承连接字符串。为避免这种情况,请考虑在<clear/>
配置部分添加connectionStrings
元素:
<connectionStrings>
<clear/>
<add name=... />
...
同样从你的堆栈跟踪中,它看起来像是SimpleMembershipProvider试图使用有问题的连接字符串。您可能希望从配置中删除SimpleMembershipProvider,或将其配置为使用其他连接字符串。