1
Answer

How to integrate mysql srver with .net (silverlight C#)

Srikanth

Srikanth

13y
2.9k
1

How to integrate mysql server in .net environment.

I am developing mobile application using silverlight windows (c# )

Can some help me in this databse integration with step by step.. need to learn this..



My sql database in silver light windows phone application-


Thanks in Advance:

 Sre
Answers (1)
0
Jaganathan Bantheswaran
NA 21.9k 2.2m 13y
Hi,

Create a WCF Service which communicates to the MySQL DB.

Access the WCF from Silverlight.

Use the MySql connection in WCF as,

private MySql.Data.MySqlClient.MySqlConnection connect_to_sql()
{
string myuid = "root";
string mypw = "";
string myserver = "localhost";
string mydb = "game1";

MySql.Data.MySqlClient.MySqlConnectionStringBuilder connstr = new MySql.Data.MySqlClient.MySqlConnectionStringBuilder();
connstr.Server = myserver; connstr.UserID = myuid; connstr.Database = mydb; connstr.Password = mypw;
MySql.Data.MySqlClient.MySqlConnection mysb = new MySql.Data.MySqlClient.MySqlConnection(connstr.ToString());
return mysb;
}


Use this,

MySql.Data.MySqlClient.MySqlConnection mysb = connect_to_sql();
mysb.Open();

sqlstr = "UPDATE game1.session" + sid + " set xco=" + xco + ", yco=" + yco + ", die=" + die + " where pid=" + pid;
MySql.Data.MySqlClient.MySqlCommand myupdcmd = new MySql.Data.MySqlClient.MySqlCommand(sqlstr, mysb);
myupdcmd.ExecuteNonQuery();
myupdcmd.Dispose();