实体框架 - 在索引0初始化字符串格式 [英] Entity Framework - Format of the initialization string at index 0

查看:552
本文介绍了实体框架 - 在索引0初始化字符串格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是例外,

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

   at System.Data.Common.DbConnectionOptions.GetKeyValuePair(String connectionString, Int32 currentPosition, StringBuilder buffer, Boolean useOdbcRules, String& keyname, String& keyvalue)
   at System.Data.Common.DbConnectionOptions.ParseInternal(Hashtable parsetable, String connectionString, Boolean buildChain, Hashtable synonyms, Boolean firstKey)
   at System.Data.Common.DbConnectionOptions..ctor(String connectionString, Hashtable synonyms, Boolean useOdbcRules)
   at System.Data.SqlClient.SqlConnectionString..ctor(String connectionString)
   at System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous)
   at System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(DbConnectionPoolKey key, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions)
   at System.Data.SqlClient.SqlConnection.ConnectionString_Set(DbConnectionPoolKey key)
   at System.Data.SqlClient.SqlConnection.set_ConnectionString(String value)
   at System.Data.Entity.Internal.LazyInternalConnection.Initialize()
   at System.Data.Entity.Internal.LazyInternalConnection.get_Connection()
   at System.Data.Entity.Infrastructure.DbContextInfo..ctor(Type contextType, DbProviderInfo modelProviderInfo, AppConfig config, DbConnectionInfo connectionInfo)
   at System.Data.Entity.Infrastructure.DbContextInfo..ctor(Type contextType, DbConnectionInfo connectionInfo)
   at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration, DbContext usersContext)
   at System.Data.Entity.MigrateDatabaseToLatestVersion`2.InitializeDatabase(TContext context)
   at System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action)
   at System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization()
   at System.Data.Entity.Internal.RetryAction`1.PerformAction(TInput input)
   at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action`1 action)
   at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
   at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
   at System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext()
   at System.Data.Entity.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider()
   at System.Linq.Queryable.OrderByDescending[TSource,TKey](IQueryable`1 source, Expression`1 keySelector)
   at Article.GetAll() in Article.cs:line 43
   at ASP._Page_Views_Home_Index_cshtml.Execute() in Index.cshtml:line 9
   at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
   at System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
   at System.Web.WebPages.StartPage.ExecutePageHierarchy()
   at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
   at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass1a.<InvokeActionResultWithFilters>b__17()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult)

我的连接字符串,

My connection string is,

  <connectionStrings>
    <add name="MyContext" connectionString="Persist Security Info=false;Integrated Security=false;Connection Timeout=4;Initial Catalog=<nice>;User ID=<nice>;pwd=<nice>;server=<nice>" providerName="System.Data.SqlClient"/>
  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="Data Source=<nice>;Initial Catalog=Master;Persist Security Info=False;User ID=<nice>;Password=<nice>;MultipleActiveResultSets=True;Application Name=EntityFramework" />
      </parameters>
    </defaultConnectionFactory>
  </entityFramework>

我不知道怎么回事。我的连接字符串是什么心不是工作?

I have no idea whats going on. What about my connection string isnt working?

!! !!更新

有趣的是 - 我发现,当我使用网络部署一个新的连接字符串和Entity Framework>默认连接工厂>参数被添加...我知道对不对?什么?!

Interestingly - I found that when I use web deploy a new Connection String and Entity Framework > Default Connection Factory > parameter gets added... I know right? What?!

我出版了生产就绪的web.config的结果是这样的:

The result of my published "production ready" web.config looks like this:

<connectionStrings>
    <add name="MyContext" connectionString="Data Source=<nice>;Initial Catalog=<nice>;Persist Security Info=False;User ID=<nice>;Password=<nice>; MultipleActiveResultSets=True;Application Name=EntityFramework" providerName="System.Data.SqlClient" />
    <add name="MyContext_DatabasePublish" connectionString="Data Source=<nice>;Initial Catalog=<nice>;Persist Security Info=False;User ID=<nice>;Password=; MultipleActiveResultSets=True;Application Name=EntityFramework" providerName="System.Data.SqlClient" />
</connectionStrings>

<entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
        <parameters>
            <parameter value="DatabasePublish" />
        </parameters>
    </defaultConnectionFactory>
    <contexts>
        <context type="MyContextDBContext, Models">
            <databaseInitializer type="System.Data.Entity.MigrateDatabaseToLatestVersion`2[[MyContextDBContext, Models], [Models.Migrations.Configuration, MyWebsite.Models]], EntityFramework, PublicKeyToken=<nice>">
                <parameters>
                    <parameter value="DatabasePublish" />
                </parameters>
            </databaseInitializer>
        </context>
    </contexts>
</entityFramework>

pretty有趣吧?

Pretty interesting huh?

现在,当公布在网站抛出连接字符串错误格式。

Now, when published the web site throws the "format of connection string error".

我想我要的是删除自动添加新的连接字符串和放大器的需求;背景和有是什么,我已经把在web配置。

I think what I want is to remove the need automated addition of the new connection string & context and have be exactly what I've put in the web config.

请告诉我最坏的是,这个所谓的功能打破了使用web.config中的变换。其实,我是来享受使用新的preVIEW转换功能。然而,即使是preVIEW确实显示了这些变化。

Whats worst is that this so-called "feature" breaks the use of web.config transforms. In fact, I've come to enjoy using the new "Preview Transform" feature. However, even the preview does show these changes.

这是怎么回事?

我可以删除吗?

推荐答案

如果您添加到Global.asax中,你应该有一个想法,什么是错的字符串。

If you add this to Global.asax, you should have an idea what is wrong with the string..

throw new Exception(ConfigurationManager.ConnectionStrings["MyContext"].ConnectionString);

如果你看到它的任何标记占位符,你应该有一个更好的主意做什么。

If you see any token place holders in it you should have a better idea what to do.

另外,还要检查SQL服务器上的权限为您的用户。

Also check the permissions on the SQL server for your user..

这篇关于实体框架 - 在索引0初始化字符串格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆