尝试连接MySQL时的安全异常(小提琴)

时间:2016-03-04 17:00:48

标签: c# mysql

我是C#的新手,我试图让这段代码在我的数据库中测试一些命令。

Fiddle here.

完整代码:

using System;
using System.Data;

using MySql.Data;
using MySql.Data.MySqlClient;

public class Tutorial2
{
    public static void Main()
    {
        string connStr = "server=localhost;user=root;database=test;port=3306;password=root;";
        MySqlConnection conn = new MySqlConnection(connStr);
        try
        {
            Console.WriteLine("Connecting to MySQL...");
            conn.Open();

            string sql = "SELECT state_user_id FROM app_state ";
            MySqlCommand cmd = new MySqlCommand(sql, conn);
            MySqlDataReader rdr = cmd.ExecuteReader();

            while (rdr.Read())
            {
                Console.WriteLine(rdr[0]+" -- "+rdr[1]);
            }
            rdr.Close();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.ToString());
        }

        conn.Close();
        Console.WriteLine("Done.");
    }
}

它无法正常工作,我在控制台中收到此错误:

Connecting to MySQL...
System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
   at MySql.Data.MySqlClient.MySqlConnection.AssertPermissions()
   at MySql.Data.MySqlClient.MySqlConnection.Open()
   at Tutorial2.Main() in d:\Windows\Temp\oup13in3.0.cs:line 16
The action that failed was:
InheritanceDemand
The type of the first permission that failed was:
System.Security.Permissions.SecurityPermission
The Zone of the assembly that failed was:
MyComputer
Done.

我该如何解决?

由于

0 个答案:

没有答案