【发布时间】:2018-02-20 09:39:46
【问题描述】:
我正在使用visual studio 2015 in asp.net mvc 4.5 中的MySQL DB 创建一个REST API。我已经完成了使用MySQL 运行 API 所需的每一步,但我遇到了这个异常。
{"Message":"发生错误。","ExceptionMessage":"初始化字符串的格式不符合从索引 121 开始的规范。","ExceptionType":" System.ArgumentException","StackTrace":" 在 System.Data.Common.DbConnectionOptions.GetKeyValuePair(String connectionString, Int32 currentPosition, StringBuilder buffer, Boolean useOdbcRules, String& keyname, String& keyvalue)\r\n 在 System.Data.Common。 DbConnectionOptions.ParseInternal(Hashtable parsetable, String connectionString, Boolean buildChain, Hashtable synonyms, Boolean firstKey)\r\n at System.Data.Common.DbConnectionOptions..ctor(String connectionString, Hashtable synonyms, Boolean useOdbcRules)\r\n at System .Data.Common.DbConnectionStringBuilder.set_ConnectionString(String value)\r\n 在 MySql.Data.MySqlClient.MySqlConnectionStringBuilder..ctor(String connStr)\r\n 在 MySql.Data.MySqlClient.MySqlConnection.set_ConnectionString(String value)\ r\n 在 System.Data.Entity.Infrastructure .Interception.DbConnectionDispatcher.b__18(DbConnection t,DbConnectionPropertyInterceptionContext
1 c)\r\n at System.Data.Entity.Infrastructure.Interception.InternalDispatcher1.Dispatch[TTarget,TInterceptionContext](TTarget 目标,Action2 operation, TInterceptionContext interceptionContext, Action3 正在执行,Action3 executed)\r\n at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.SetConnectionString(DbConnection connection, DbConnectionPropertyInterceptionContext1 interceptionContext)\r\n 在 System.Data.Entity .Internal.LazyInternalConnection.InitializeFromConnectionStringSetting(ConnectionStringSettings appConfigConnection)\r\n 在 System.Data.Entity.Internal.LazyInternalConnection.TryInitializeFromAppConfig(字符串名称,AppConfig 配置)\r\n 在 System.Data.Entity.Internal.LazyInternalConnection.Initialize( )\r\n 在 System.Data.Entity.Internal.LazyInternalConnection.CreateObjectContextFromConnectionModel()\r\n 在 System.Data.Entity.Internal.LazyInternalContext.InitializeContext()\r\n 在 System.Data.Entity.Internal。 InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)\r\n 在 System.Data.Entity.Internal.Linq.InternalSet1.Initialize()\r\n at System.Data.Entity.Internal.Linq.InternalSet1.GetEnumerator()\r\n 在 System.Data.Entity.Infrastructure.DbQuery1.System.Collections.Generic.IEnumerable<TResult>.GetEnumerator()\r\n at System.Collections.Generic.List1。 .ctor (IEnumerable1 collection)\r\n at System.Linq.Enumerable.ToList[TSource](IEnumerable1 来源)\r\n 在 D:\Work\DOT NET API\RestWithMySQL\RestWithMySQL\Controllers\ProductsController.cs:line 19 中的 RestWithMySQL.Controllers.ProductsController.Get()"}
我认为我的连接字符串有问题。我已经搜索过了,但找不到确切的解决方案。
<connectionStrings>
<!--<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-RestWithMySQL-20170911031521.mdf;Initial Catalog=aspnet-RestWithMySQL-20170911031521;Integrated Security=True" providerName="System.Data.SqlClient" />-->
<add name="ProductEntities" connectionString="metadata=res://*/ProductsModel.csdl|res://*/ProductsModel.ssdl|res://*/ProductsModel.msl;provider=MySql.Data.MySqlClient;provider connection string=" server=localhost;user id=root;database=accurate_dev;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework" providerName="MySql.Data.MySqlClient"/>
<!--<remove name="LocalMySqlServer" /><add name="LocalMySqlServer" connectionString="" providerName="MySql.Data.MySqlClient" />-->
</connectionStrings>
任何帮助将不胜感激。
【问题讨论】:
-
不确定这是否是问题,但您是否尝试将
&quot;更改为"?