Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/297.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# 在ASP.NET 4.5中使用LINQ和MySql_C#_Mysql_Linq - Fatal编程技术网

C# 在ASP.NET 4.5中使用LINQ和MySql

C# 在ASP.NET 4.5中使用LINQ和MySql,c#,mysql,linq,C#,Mysql,Linq,当我尝试使用LINQ的DataContext和连接字符串连接到MySql数据库时,由于无法找到网络路径,它在运行时失败。当我连接到MS SQL数据库时,这项功能就可以使用了。它在运行时失败,但出现以下异常: System.Data.SqlClient.SqlException: 'A network-related or instance-specific error occurred while establishing a connection to SQL Server. The serv

当我尝试使用LINQ的DataContext和连接字符串连接到MySql数据库时,由于无法找到网络路径,它在运行时失败。当我连接到MS SQL数据库时,这项功能就可以使用了。它在运行时失败,但出现以下异常:

System.Data.SqlClient.SqlException: 'A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)'

Inner Exception
Win32Exception: The network path was not found
失败代码:

DataContext db = new DataContext(connectionString);
Table<FlightPriceModel> flightsTable = db.GetTable<FlightPriceModel>();
IQueryable<FlightPriceModel> query = from row in flightsTable select row;
return "Number of rows in FlightPrices table: " + query.Count();
连接字符串如下所示:

Database={database_name};Data Source={webhost.net};User Id={mysql_user};Password={password}
在my.csproj中,我使用以下引用作为


我怀疑LINQ不知道我正在尝试连接到MySql数据库,并且正在尝试像使用MS SQL数据库一样使用连接字符串。有没有办法将LINQ的DataContext用于MySql数据库?

您正在连接MySql数据库,并且从“System.Data.SqlClient.SqlException”中生成错误,这意味着它无法连接MySql数据库并尝试连接Sql数据库

尝试在服务器资源管理器中通过DataConnection添加MySql数据库

如果您无法获得此选项,则必须安装“Visual studio MySql连接器”
成功安装后,重新启动VS。

您的DbContext不知道要使用哪个提供程序。您需要使用正确的提供程序名称更新配置文件。试试这个-你能发布你的整个连接字符串xml(带有提供者名称)吗?谢谢你的回复,我没有选择MySQL数据库的选项。Visual Studio MySQL连接器目前不支持VS 2017,但下一版本将:
Database={database_name};Data Source={webhost.net};User Id={mysql_user};Password={password}
MySql.Data
MySql.Data.Entity.EF6
MySql.Web