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?
thankshere 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 MissingSchemaActi开发者_如何学运维on 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");
SOLVED: apparently SqlConnection is not made for MySQL
use: MySqlConnection instead
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");
精彩评论