1

I have some problems with connecting to my local DB using c# System.Data.SqlClient.

Information:

  • DB parameters: Name:baza Host:localhost Instance:baza Port:3306 Schema:world
  • My connection string: @"server=localhost\baza;password=pass;User Id=root;database=world;Persist Security Info=True"
  • using: c#, System.Data.SqlClient, MySQL Workbench
  • firewall off
  • succesfull conection with JDBC, so server is working

JDBC parameters:

String url = "jdbc:mysql://localhost:3306/";
String driver = "com.mysql.jdbc.Driver";
String dbName = "world";
String username = "root";
String pass = "pass";

Problem:

  • when I use conn.Open(); this happen => (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

Tried:

I have no idea what to do... Sth is probably with server name.

EDIT: code:

string connstr = @"Data Source=localhost\baza;password=qspass;User Id=root;"+
    "Initial Catalog=world;Persist Security Info=True";

Console.WriteLine(connstr);

SqlConnection conn = new SqlConnection(conbuild.ConnectionString);
conn.Open();

Console.WriteLine("YO!");
Some more code...

Never reached YO! :P

1
  • 1
    The System.Data.SqlClient namespace is the.NET Framework Data Provider for SQL Server, not MySQL. If you are using MySQL, you will need to use the MySQL ADO.NET driver available here: dev.mysql.com/downloads/connector/net Commented Apr 5, 2013 at 10:30

1 Answer 1

2

I suppose I should put my answer in the answer section, rather than a comment :)

I see from your JDBC connection string that you are using MySQL rather than SQL Server.

The System.Data.SqlClient namespace is the.NET Framework Data Provider for SQL Server, not MySQL.

If you are using MySQL, you will need to use the MySQL ADO.NET driver available here:

Download Connector/Net

Sign up to request clarification or add additional context in comments.

2 Comments

I dont get it, im dumb. How use it? I have it already installed... Like using this MySql.Data in my code?
I can't explain all that to you here, MySQL provide tutorials on how to use it, see here: dev.mysql.com/doc/refman/5.6/en/connector-net-tutorials.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.