How to connect to a distant mysql database using asp.net [duplicate] - c#

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).

Related

C# MySQL MySqlConnection connectionstring for empty password [duplicate]

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

Invalid connection string [duplicate]

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

How can I determine whether Stored Procedure Parameter is optional from C# code (I am using Sql Server) [duplicate]

This question already has answers here:
How can I determine if a SQL Server stored procedure parameter has a default?
(7 answers)
Closed 7 years ago.
I am using C# to connect to Sql Server. I am trying to get Parameter Details of stored procedure before calling the stored procedure. Can you please help me regarding how I can get to know whether any SP parameter is optional or not form C# code itself.
I am using loaclDb in VS 2013. I have Data Source and Db File Name available.
TIA.
You may do like this way:
Server servev = new Server("YourServerName");
Database dataBase = servev .Databases["YourDatabase"];
var paramData = dataBase.StoredProcedures["YourProcedureName"].Parameters;
foreach(StoredProcedureParameter param in param) {
string paramName=param.Name;
string paramValue=param.DefaultValue;
}

See all databases from SQL connection string [duplicate]

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.

Can connect to mySql server via php but not with c# [duplicate]

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;"

Categories