0
votes

i'm using Visual Studio 2010 and when i bind a DataGridView with my remote mysql db it works fine.
but when i take the connection string from the wizard and try to use it with code i get: "provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server"

this is the connection string i try (i tried many variants):
"Server=myserver.org;Database=my_db;Uid=myuser;Pwd=mypwd;"

any ideas?
thanks

here is the code:
string connectionString = "Server = sql.server.org; Database = my_db; Uid = my_user; Pwd = mypwd;";

        SqlConnection myConnection = new SqlConnection(connectionString);
        SqlDataAdapter mySqlDataAdapter = new SqlDataAdapter("Select * from Table", myConnection);
        DataSet myDataSet = new DataSet();
        DataRow myDataRow;

        // Create command builder. This line automatically generates the update commands for you, so you don't 
        // have to provide or create your own.
        SqlCommandBuilder mySqlCommandBuilder = new SqlCommandBuilder(mySqlDataAdapter);

        // Set the MissingSchemaAction property to AddWithKey because Fill will not cause primary
        // key & unique key information to be retrieved unless AddWithKey is specified.
        mySqlDataAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;

        mySqlDataAdapter.Fill(myDataSet, "Table");
2
Could you show the non-working code?Darin Dimitrov

2 Answers

0
votes

SOLVED: apparently SqlConnection is not made for MySQL

use: MySqlConnection instead

0
votes
           string connectionString = "server=localhost;uid=root;pwd=***********;database=terra_incognita_online";
           MySqlConnection sqlConnection = new MySqlConnection();
           sqlConnection.ConnectionString = connectionString;
           sqlConnection.Open();
           Console.WriteLine("open");
           sqlConnection.Close();
           Console.WriteLine("close");