I have set up a small test data base (local) using MS SQL Server, code bellow.
Code here
SqlConnection cs = new SqlConnection(@"Data Source = .\SQLEXPRESS; Initial Catalog = OMS; Integrated Security = true");
SqlDataAdapter da = new SqlDataAdapter ();
da.InsertCommand = new SqlCommand("INSERT INTO Customer(FirstName,LastName) VALUES (@FirstName,@LastName)", cs);
da.InsertCommand.Parameters.Add("@FirstName", SqlDbType.VarChar).Value = firstname.Text;
da.InsertCommand.Parameters.Add("@LastName", SqlDbType.VarChar).Value = lastname.Text;
This is working well, now I have set up a MYSQL database hosted on a live server. I have installed the MYSQL connector I need for visual studios and have connected to the data base. what I now wish to know is how to alter my connection string to pace the data into the live database. I tried to put my host IP in eg:
SqlConnection cs = new SqlConnection(@"Data Source = 000.000.00.000; Initial Catalog = database name; Integrated Security = true");
However this is not working, any idea on what code I should use to connect to a live server? any help would be appreciated.
Please refer to the link on dev.mysql
http://dev.mysql.com/doc/refman/5.0/en/connector-net-programming-connecting-connection-string.html
and
The answer to your question is mostly related to the settings of the server and/or database. Make sure:
When all this is checked, the connection string should be altered to something like:
"Data Source=123.456.789.012;Initial Catalog=testdb; password=password; user id=login;"
This works fine for me, to connect with MSSQL2012 remote server database, since you are mixing MySQL and MSSQL, there could occur some other MySQL specific options.
EDIT: from what I see you did in comments to other answer, CHECK TWICE, how you handle the port -> you are using a comma in the ip string, whereas i hope you should avoid using it or use colon.
all working thanks to some great advice. working code for reference
{
MySqlConnection cs = new MySqlConnection(@"Data Source = 000.000.00.000;username=*******;password=******; Initial Catalog = database; Integrated Security = true");
MySqlDataAdapter da = new MySqlDataAdapter ();
da.InsertCommand = new MySqlCommand("INSERT INTO Customer(FirstName,LastName) VALUES (@FirstName,@LastName)", cs);
da.InsertCommand.Parameters.Add("@FirstName", MySqlDbType.VarChar).Value = firstname.Text;
da.InsertCommand.Parameters.Add("@LastName", MySqlDbType.VarChar).Value = lastname.Text;
cs.Open();
da.InsertCommand.ExecuteNonQuery();
cs.Close();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.