mysql - 如何使我的数据库连接正常工作?

标签 mysql azure

我在 AZURE 帐户中设置了 MySQL 数据库,但无法以任何方式连接它。我尝试过:

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            SqlConnection sqlconnection = new SqlConnection("Database=Banco1; Data Source=br-cdbr-azure-south-a.cloudapp.net;User Id=USERID Password=PASSWORDid");
            Console.WriteLine("1");
            sqlconnection.Open();
            Console.WriteLine("2");
            SqlCommand cmd = new SqlCommand("CREATE TABLE Customer(First_Name char(50), Last_Name char(50), Address char(50), City char(50), Country char(25), Birth_Date datetime); ", sqlconnection);
            Console.WriteLine("3");
            cmd.ExecuteNonQuery();
            Console.WriteLine("4");
            Console.ReadLine();
        }
    }
}

我尝试通过命令进行打印,但程序仅打印“1”,这意味着我无法打开连接...我该如何解决这个问题?

输出错误:

An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll

Additional information: Error in the network or specifics to the instance when stablishing conexion to the SQL Server. The server was not found or was not avaible. Check if the instance name is correct and if the SQL Server is configured to allow remote conexions. (provider: Named Pipes Provider, error: 40 - Could not stablish connection to SQL Server)

最佳答案

SqlConnection用于连接SQL数据库,对于MySQL数据库,需要使用MySqlConnection。请先安装MySql Connect/NET然后添加引用enter image description here

现在您可以使用以下代码成功连接到您的Mysql数据库:

MySqlConnection con = new MySqlConnection("your_mysql-connect_string");

关于mysql - 如何使我的数据库连接正常工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34909271/

相关文章:

azure - Azure 上的 Asp.Net Core 2.0 结果为 502.5

javascript - d3.js 从 url 获取 JSON

python - 使用 python 在 Azure Event Hub 中收集 Websocket 流数据

node.js - NodeJS 多方文件上传到 Azure 和文本字段

PHP 查询在使用两个 WHERE 子句限制查询时显示没有日期的行

mysql - 什么是 SQL Server UPDATE() 触发器函数的 MySQL 等价物?

mySQL 查询优化 LEFT JOIN

mysql - 如何锁定 DBIx :Class? 中的表

python - 限制 Azure 应用程序访问 OneDrive 中的特定文件夹

mysql "memory usage"越来越大