By admin on March 10, 2011
I’m currently connected to a local Microsoft SQL server. I’m new to windows programming and i need the code snippets to connect my windows C# application to a remote Mysql database. I have a website which is connected to my web host’s Mysql database. I want to be able to connect my windows C# app. to that same data base. Need your expert advice. By the way, I’m using visual studio.
Posted in Remote Web Hosting | Tagged application, code snippets, microsoft sql server, Programming, sql, windows c |
Incoming search terms:
Powered By Pligg business loans, pligg content management system physics projects, Powered By Pligg meaning, powered by vBulletin best business home opportunity, powered by vBulletin business loans, powered by SMF code, Powered By Pligg exercise, pligg content management system internet home based business, Powered By Pligg free sound card, pligg content management system small business financing
It’s the same for a remote database as local. When you set up the data source, just specify the remote server.
You need to install the drivers to setup an ODBC connection which can be found here:
http://www.mysql.com/products/connector/
After you have the drivers installed, setup your DSN to connect to your remote mysql database. You will likely need to add your ip to the Remote Database Access Hosts depending on how the Mysql server is configured.
You will then be able to use code as follows (replace the DSN name “test” with the name you provide when creating the DSN):
using System.Data.Odbc;
OdbcConnection DbConnection = new OdbcConnection(“DSN=test”);
DbConnection.Open();
OdbcCommand DbCommand = DbCommand.CommandText = “SELECT * FROM TABLE”;
OdbcDataReader DbReader = DbCommand.ExecuteReader();DbConnection.CreateCommand();