I've got an SQL server and database setup on an external server (let's call the domain name "hello.com" for the purposes of this), and I want to connect to this server via a C# program. So far I have this (All server/database details are different to the real ones):
private static void SetupSQL()
{
string connectionString = "server=hello.com; database=db1; uid=user1; pwd=xxxxx;";
connection = new SqlConnection();
connection.ConnectionString = connectionString;
try
{
connection.Open();
Console.WriteLine("Connected");
}
catch (Exception e)
{
Console.WriteLine(e.Message.ToString());
}
}
This is giving me an error message:
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
I have checked all the connection string, and I am allowed remote access, as I have SQLWorkbench open querying the database right now on the same computer.
Any ideas?
You'll need the MySQL
driver:
http://dev.mysql.com/downloads/connector/net/
You can then use the the MySqlConnection
connection class to connect.
MySqlConnection connection = new MySqlConnection(connectionString);
http://www.codeproject.com/Articles/43438/Connect-C-to-MySQL
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With