Zulukas Zulukas - 2 years ago 150
C# Question

Querying a website database from a C# console application

I'm trying to write a simple app in C# that will query a database available to the public located at https://newswire.theunderminejournal.com/

They give an example located at https://newswire.theunderminejournal.com/sample2.php

As far as I know, the server I'm trying to connect to is "newswire.theunderminejournal.com" and the database is "newsstand".

This gives me a string of:

string connection_str ="Server=newsstand.theunderminejournal.com;Database=newsstand";

My code looks like this:

xData = "Unable to connect to database.";
string server = "'newswire.theunderminejournal.com'";
//string server = "";
string database = "'newsstand'";
string connection_str = string.Format("Server={0};Database={1};", server, database);

SqlConnection connection = new SqlConnection(connection_str);

xData = "Connection established!";
catch(Exception e)
xData = e.Message;


This results only in an error message:

"A network-related or instance-specific error occured while not
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

I've pinged the server, getting an IP address at and no issues at all pinging it.

Is there something obvious I'm missing here? I'm brand new to C# so if there is another/better way of doing this, I'd appreciate it!


Answer Source

You cannot create a SqlConnection to a mySQL database, which is why the error message refers to "… establishing a connection to SQL Server.".

You need to use a MySqlConnection instead, which you get when you install Connector/Net - which you can download from Oracle here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download