2 Replies - 741 Views - Last Post: 07 August 2012 - 12:50 AM Rate Topic: -----

#1 mdavies1983  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 27-June 12

Can't Connect to SQL Database

Posted 06 August 2012 - 07:41 AM

I am currently working on a project to convert an old Excel tool into a more stable C# application. In the existing Excel tool it connects to a sql database via ODBC with the following connection string:

Set conn = New ADODB.Connection
conn.Open DRIVER={MySQL ODBC 5.1 Driver};SERVER=test.server.com;DATABASE=dbname;USER=username;PASSWORD=password;Option=3"


I'm now trying (unsuccessfully) to connect to the sql database via C# with the following connection string:

System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection();
conn.ConnectionString = "integrated security=SSPI;data source=test.server.com;persist security info=False;initial catalog=dbname;user id=username;password=password;"
conn.Open();


The error message I receive says that it failed to connect to data source. The server was not found or was not accessible. I've been pulling my hair out with this for a good few hours now and can't see what I'm missing.

Is This A Good Question/Topic? 0
  • +

Replies To: Can't Connect to SQL Database

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3534
  • View blog
  • Posts: 10,941
  • Joined: 05-May 12

Re: Can't Connect to SQL Database

Posted 06 August 2012 - 09:35 AM

The SqlConnection class is meant to connect to the Microsoft SQL Server.

You may want to use the MySQL Connecter/Net, and use the MySqlConnection class.

Alternately, you can try using the
OdbcConnection class since you were using the ODBC driver previously.
Was This Post Helpful? 1
  • +
  • -

#3 mdavies1983  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 27-June 12

Re: Can't Connect to SQL Database

Posted 07 August 2012 - 12:50 AM

I opted for the ODBC approach and have it working now. Thank you!

string myConnString = "DRIVER={MySQL ODBC 5.1 Driver};SERVER=test.server.com;DATABASE=dbname;USER=username; PASSWORD=password;OPTION=3;";
OdbcConnection myConnection = new OdbcConnection(myConnString);
myConnection.Open();

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1