简体   繁体   中英

Can not connect to local database with c# System.Data.SqlClient

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM