I am using Visual Studio Code, and I'm trying to connect to my MySql server (5.5). I have downloaded the latest (6.10.6) MySql connector and installed it. I had to research to add references in VS Code, but I managed it. Now my .csproj file looks like this:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Reference Include="LibMySql.Data.dll">
<HintPath>MySql.Data</HintPath>
<SpecificVersion>False</SpecificVersion>
</Reference>
</ItemGroup>
</Project>
I have copied the content of C:Program Files (x86)MySQLMySQL Connector Net 6.10.6Assembliesv4.5.2 to myProjectLib. At compile time there are no errors, all green. But when I try to connect using this code
using System.Data;
using System.Security.Permissions;
using MySql.Data;
using MySql.Data.MySqlClient;
public static bool Connect(){
string str = "server=192.168.0.160;user=usr;database=DB;port=3306;password=pass";
MySqlConnection connection = new MySqlConnection(str);
connection.Open();
System.Console.WriteLine(connection.State);
return true;
}
it fails, and produces this error:
An unhandled exception of type 'System.IO.FileNotFoundException' occurred in MySql.Data.dll: 'Could not load file or assembly 'System.Security.Permissions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system can't find the file.'
I do not know why, as the using directive is not signaling an error.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…