-1

I set up a MySQL database in my AZURE account, but I cannot connect it in any way. I tried:

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();
        }
    }
}

I tried putting prints through the commands, and the program only prints "1" which means I can't get the connection opened... how can I fix that?

The output error:

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 connection to the SQL Server. The server was not found or was not available. Check if the instance name is correct and if the SQL Server is configured to allow remote connection. (provider: Named Pipes Provider, error: 40 - Could not stablish connection to SQL Server)

4
  • What language is this? Edit your question and add an appropriate tag. Commented Jan 20, 2016 at 20:39
  • Please edit your question to include more detail, such as the actual error you're getting. Also, where did you set up MySQL: In a VM? If so, how did you open a port to it? As your question currently stands, it's unclear what you're asking, and risks being closed. Commented Jan 20, 2016 at 20:47
  • @miken32 - looks like c# but I don't think that's relevant. Commented Jan 20, 2016 at 20:47
  • As a matter of fact it is C#, The problem seems to be not stablishing a server... It should be in a VM, but I cannot find it. Commented Jan 20, 2016 at 21:05

1 Answer 1

1

SqlConnection is used for connecting SQL Database, for MySQL Database, you need to use MySqlConnection. Please first install MySql Connect/NET and then add reference enter image description here

Now you can connect to your Mysql database successfully with the code below:

MySqlConnection con = new MySqlConnection("your_mysql-connect_string");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.