首页 新闻 会员 周边

DbContext(string nameOrConnectionString);问题

0
悬赏园豆:5 [待解决问题]

由于是winform  所以不想把连接字符串在 config文件中进行配置,想在代码里面写死,连接的是mysql数据库,不知该如何设置 

 

 

private static string ConnectStr()
{
string connectStr = "Server="
+ "127.0.0.1" + ";port=3306;DataBase="
+ "dbtest1" + ";persist security info=True;user id="
+ "root" + ";password="
+ "123456" + ";Allow Zero Datetime=true;Allow User Variables=True;Charset=utf8;";
return connectStr;
}

public DBContext()
//: base("name=connectionString")
: base(ConnectStr())
{
}

 

这里居然报 "不支持关键字: “port”。"

 

做过的请回答 

晓道的主页 晓道 | 菜鸟二级 | 园豆:297
提问于:2017-04-21 10:45
< >
分享
所有回答(1)
0

+ "127.0.0.1" + ";port=3306;DataBase="

改成

+ "127.0.0.1:3306" + ";DataBase="

正怒月神 | 园豆:183 (初学一级) | 2017-04-21 11:35

No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlClient'. Make sure the provider is registered in the 'entityFramework' section of the application config file. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.

 

 

觉得是应该要指定  providerName=MySql.Data.MySqlClient;

支持(1) 反对(0) 晓道 | 园豆:297 (菜鸟二级) | 2017-04-21 11:51

否则默认是    EntityFramework.SqlServer

支持(0) 反对(1) 晓道 | 园豆:297 (菜鸟二级) | 2017-04-21 11:52

@晓道: System.ArgumentException:“不支持关键字: “providername”。”

支持(0) 反对(0) 李0539 | 园豆:442 (菜鸟二级) | 2019-04-29 15:01
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册