0

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");
1
  • Could you show the non-working code? Commented Sep 18, 2010 at 12:34

2 Answers 2

0

SOLVED: apparently SqlConnection is not made for MySQL

use: MySqlConnection instead

Sign up to request clarification or add additional context in comments.

Comments

0
           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");

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.