This question already has an answer here:
What may cause the KeyNotFoundException when trying to open a MySQL connection
(1 answer)
Closed 2 years ago.
I am trying to connect C# and database MySQL : using MySql.Data.MySqlClient;
My codes are as below. I am getting error. I think it is because of empty password.
string connstring = #"server=localhost;userid=root;password=;database=client";
MySqlConnection dbcon = new MySqlConnection(connstring);
if you don't want to expose the password in connect string. you can use the Windows authentication instead.
https://learn.microsoft.com/en-us/dotnet/framework/data/adonet/sql/authentication-in-sql-server
Related
This question already has answers here:
Connecting to a mySQL database using asp.net
(2 answers)
Closed 6 years ago.
I want to connect to a disant mysql database wich is located in another server using Asp.net C#.
How can i did it ?
Thanks.
You need this code:
var myConnectionString = "server=127.0.0.1;uid=root;pwd=12345;database=test;";
var conn = new MySqlConnection(myConnectionString);
conn.Open();
Also you need the public IP of the MySql server and the correct credentials (userid, password and database name).
This question already has an answer here:
SQL Server connection string
(1 answer)
Closed 6 years ago.
Apparently this connection string is incorrect?
connectionString="Server=mydb.com:1433/sqlExpress;Database=d;User Id=d;Password=pw;"
the first think that I see is that you have type wrong this part
Server=mydb.com:1433
use
Server=mydb.com,1433
the sql server use the comma to separate the port.
Also take a look at that answer: Setting up connection string in ASP.NET to SQL SERVER
This question already has answers here:
C# connect to database and list the databases [duplicate]
(6 answers)
Closed 8 years ago.
I have 3 databases attached to my SQL instance. From my application the C# connection string is:
SqlConnection conn = new SqlConnection();
conn.ConnectionString = #"Data Source=server\SQLEXPRESS;Initial Catalog=Database1;Integrated Security=True";
Mr problem is my SQL scripts reference the other attached databases and some of my scripts are based on a dynamic USE statement to look at a different attached database.
Is there anyway to make the connection string see all attached databases so my SQL scripts I run through the connection string can query other databases besides the specified initial Catalog database?
Thank you
I suggest you add all connection strings in config file and call them as needed.
This question already has answers here:
How to form a correct MySQL connection string? [closed]
(3 answers)
Closed 8 years ago.
As I wrote in the topic, this works totally fine:
mysql_connect("server","username","password");
But this doesn't:
MySql.Data.MySqlClient.MySqlConnection connection =
new MySql.Data.MySqlClient.MySqlConnection("SERVER=server;DATABASE=database;UID=username;PASSWORD=password;");
connection.Open();
The exception is always
Unable to connect to any of the specified MySQL hosts
And no, the question is neither a duplicate, nor answered there
As per the documentation, this
"SERVER=server;DATABASE=database;UID=username;PASSWORD=password;"
should be
"SERVER=server;DATABASE=database;UID=username;PWD=password;"
This question already has answers here:
ExecuteReader requires an open and available Connection. The connection's current state is closed
(3 answers)
Closed 8 years ago.
I have a SQL Server 2008 R2 running but when I try to connect to the server via my C# connection string I receive an error. I have no clue of what the problem is!
Here is my connection string:
_msConnection = new SqlConnection("Server=ServerIpAdress;Database=DataBaseName;User Id=NetworkName\\UserName;Password=PW;");
I hope some of you guys can help me?
Have a great day you all!
Id=NetworkName\\UserName
sounds a bit strange, try
Id=username
Also if you can connect to the DB using MS VS, MS SMS or any other likely tools your app can connect passin exactly same paramenters.
Other things to check: Actual user running the app (IIS_USR maybe)
In your SMS or VS you can get the actual connection string being used and just copy past it.