Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# MySql和实体框架代码优先_C#_Mysql_Frameworks_Entity - Fatal编程技术网

C# MySql和实体框架代码优先

C# MySql和实体框架代码优先,c#,mysql,frameworks,entity,C#,Mysql,Frameworks,Entity,我首先遇到MySql和实体框架代码的问题 web.config.xml中的我的连接字符串 <add name="EntityContext" connectionString="Server=127.0.0.1; port=8080 Database=simple_crud; Uid=root; Pwd=;" providerName="MySql.Data.MySqlClient" /> 我的控制器 public EntityContext db = new EntityCont

我首先遇到MySql和实体框架代码的问题

web.config.xml中的我的连接字符串

<add name="EntityContext" connectionString="Server=127.0.0.1; port=8080 Database=simple_crud; Uid=root; Pwd=;" providerName="MySql.Data.MySqlClient" />
我的控制器

public EntityContext db = new EntityContext();

public ActionResult Index()
{
     List<Pessoa> pessoas = db.Pessoas.ToList(); // here is the error
     return View(pessoas);
}
public EntityContext db=new EntityContext();
公共行动结果索引()
{
List pessoas=db.pessoas.ToList();//下面是错误
返回视图(pessoas);
}
所以,当我按下F5键时,我得到了这样的信息:“输入字符串的格式不正确”

我想念什么

更新

堆栈跟踪:

[格式异常:输入字符串的格式不正确。]
System.Number.stringtonNumber(字符串str,NumberStyles选项, NumberBuffer&number,NumberFormatInfo信息,布尔值(十进制) +9591147 System.Number.ParseUInt32(字符串值、NumberStyles选项、NumberFormatInfo numfmt)+119
System.String.System.IConvertible.ToUInt32(IFormatProvider) +46 System.Convert.ChangeType(对象值、类型转换类型、IFormatProvider提供程序)+9509065
MySql.Data.MySqlClient.MySqlConnectionStringBuilder.ChangeType(对象 值,类型t)+240
MySql.Data.MySqlClient.MySqlConnectionStringBuilder.SetValue(字符串 关键字,对象值)+399
MySql.Data.MySqlClient.MySqlConnectionStringBuilder.set_项(字符串 关键词,对象值)+54
System.Data.Common.DbConnectionStringBuilder.set\u ConnectionString(字符串 值)+127
MySql.Data.MySqlClient.MySqlConnection.set_ConnectionString(字符串 值)+289
System.Data.Entity.Internal.LazyInternalConnection.TryInitializeFromAppConfig(字符串 名称)+409
System.Data.Entity.Internal.LazyInternalConnection.Initialize()+49
System.Data.Entity.Internal.LazyInternalConnection.get_ConnectionHasModel() +10 System.Data.Entity.Internal.LazyInternalContext.InitializeContext() +265 System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(类型 entityType)+17
System.Data.Entity.Internal.Linq.InternalSet
1.Initialize()+62
System.Data.Entity.Internal.Linq.InternalSet
1.GetEnumerator()+15
System.Data.Entity.Infrastructure.DbQuery
1.System.Collections.Generic.IEnumerable.GetEnumerator()
+40 System.Collections.Generic.List
1..ctor(IEnumerable
1 collection)+315 System.Linq.Enumerable.ToList(IEnumerable
1 collection source)+58 SimpleMysqlCrud.Controllers.PessoaController.Index()中的 f:\users\pablo.rocha.fti\documents\visualstudio 2010\Projects\SimpleMysqlCrud\SimpleMysqlCrud\Controllers\PessoaController.cs:16 lambda_方法(闭包、控制器库、对象[])+62
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase 控制器,对象[]参数)+17
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext,IDictionary
2参数)+208
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext,ActionDescriptor ActionDescriptor,IDictionary
2 参数)+27
System.Web.Mvc.c_DisplayClass15.b_12() +55 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter 过滤器,ActionExecutingContext预文本,Func
1 continuation)+263
System.Web.Mvc.c__显示类17.b__14() +19 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext,IList
1过滤器,ActionDescriptor ActionDescriptor, IDictionary
2参数)+191
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext,字符串actionName)+343
System.Web.Mvc.Controller.ExecuteCore()+116
System.Web.Mvc.ControllerBase.Execute(RequestContext-RequestContext) +97 System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext 请求上下文)+10
System.Web.Mvc.c__DisplayClassb.b__5()+37
System.Web.Mvc.Async.c__显示类1.b__0()+21
System.Web.Mvc.Async.c__显示类8
1.b__7(IAsyncResult )+12 System.Web.Mvc.Async.WrappedAsyncResult`1.End()+62 System.Web.Mvc.c_DisplayClasse.b_d()+50
System.Web.Mvc.SecurityUtil.b_0(操作f)+7 System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(操作) +22 System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)+60
System.Web.Mvc.MvcHandler.System.Web.IHTTPassynchandler.EndProcessRequest(IAsyncResult 结果)+9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8970141 System.Web.HttpApplication.ExecuteStep(IExecutionStep步骤,布尔值&同步完成)+184


将所有评论收集到答案中

在端口=3306后添加分号;并检查您的mysql侦听端口(可能是3306,mysql默认值?)。生成的连接字符串:

<add name="EntityContext" connectionString="Server=127.0.0.1; port=3306; Database=simple_crud; Uid=root; Pwd=;" providerName="MySql.Data.MySqlClient" />

MySql默认端口为3306;所以这里不用提这个

例如:



哪一行是异常?您忘记在端口=8080否后添加分号了?@Andreyvolshin,请给我一个例子。@DStanley,异常在这里:db.Pessoas.ToList()请同时发布堆栈跟踪。端口是默认值。没有必要把
public EntityContext db = new EntityContext();

public ActionResult Index()
{
     List<Pessoa> pessoas = db.Pessoas.ToList(); // here is the error
     return View(pessoas);
}
<add name="EntityContext" connectionString="Server=127.0.0.1; port=3306; Database=simple_crud; Uid=root; Pwd=;" providerName="MySql.Data.MySqlClient" />
<add name="DefaultConnection" providerName="MySql.Data.MySqlClient" connectionString="SERVER=localhost;DATABASE=testdb;UID=test;PASSWORD=test123;" />