当我尝试使用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();当我直接使用MySqlConnection时,它是有效的,所以我知道我的连接字符串和服务器配置是好的:
MySqlConnection conn = new MySqlConnection(connectionString);
conn.Open();
conn.Close();
return "Test successful.";连接字符串如下所示:
Database={database_name};Data Source={webhost.net};User Id={mysql_user};Password={password}在我的.csproj中,我使用了以下引用作为MySql Connector 6.9.9 installer的一部分
MySql.Data
MySql.Data.Entity.EF6
MySql.Web我怀疑LINQ不知道我正在尝试连接到MySql数据库,并试图像在MS SQL数据库中一样使用连接字符串。有没有办法在MySql数据库中使用LINQ的DataContext?
发布于 2017-04-04 15:13:59
您正在连接MySql数据库,并且错误生成率来自“System.Data.SqlClient.SqlException”,这意味着它无法连接MySql数据库并尝试连接到Sql数据库。
尝试在服务器资源管理器中通过DataConnection添加MySql数据库

如果你不会得到这个选项,那么你必须在成功安装重启VS后安装"Visual studio MySql连接器“。
https://stackoverflow.com/questions/43198800
复制相似问题