How to connect to a MySQL server using C#? - c#

I have a C# Application which would access a MySQL server on another computer. I am trying to do it via IP. Here is my Connection String :
result = "server =66.45.233.226; user id=testcampuscrm; password =Daph$5656; database=testcampuscrm; convert zero datetime=true; ";
getting error this
Access denied for user 'testcampuscrm'#'66.45.232.178' (using
password: YES)
My code is anther hosting and mysql database anther hostig please help us. Thanks

There is multiple things you have to take into consideration while accessing mysql from another machine some them are -
Assuming you did write correct code
1.Change mysql config (my.ini) to receive packets from all IP
2.Add firewall Exception for port 3306 on machine where Mysql is Hosted
3.User name password is Correct and granted proper privileges.
PS:-Do not share server credentials on public forums

Related

How to Connect SQL server from client to Server PC using Connection string in C#

I am trying to connect SQL Server from Client PC using the below-mentioned string, but it Is showing error as "Login failed for user 'sa'"
Tried string:
public static string connString = #"Data Source=(eg.IP)10.0.255.255,1433; Network Library=DBMSSOCN;Initial Catalog=InventoryProjects;User Id=sa;Password=password";
I have provided IP , userid and passward are correct.
Happening:
DB is not connected from Client PC.
Expectation:
But it should connect as I expected.
Can Anyone Please guiding me to proceed Further, because I am not very much familiar in C# and SQL
Points that spring to mind:
(eg.IP) should be removed from the connection string
Is IP address correct - may not be if it is dynamic?
Is the user id and password correct - use of sa user id may not be allowed?
Check - if you are able to run Microsoft SQL Server Management Studio to connect to the SQL database and check the connection string.

How Connect to a database

I need to access my database which is located in University central server. University gave me the ip address and also root access and the password. I don't Have the port address,i know to connect to a database with port address like this,i Used this Connection String to connect multiple computers and it works,but Want to connect my database through the univercity server
Data Source=192.168.1.1,2222\SQLEXPRESS;Initial Catalog=Temp_project;Persist Security Info=True;User ID=userid;Password=password
This is the example connection string that will work with MS Sql database:
"Server=tcp:<domain/IP>,1433;Initial Catalog=<databaseName>;Persist SecurityInfo=False;UserID=<myUser>;Password=<myPassword>;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"
Addressing your info that u got 10.10.X.X Ip and u dont know mucha about networking - If u want to reach IP like this (10.10.X.X), you need to be in same network with the PC where database is located. Simply said - you have to be or in the university network or use a VPN connection.

remote connection to mysql

i have two machine
PC#1 with db mysql and appache and PC#2 with a c# form try to connect to this db
here is my connection string used in PC#2: SERVER=My_public_ip;DATABASE = my_test; UID = root; PASSWORD = xxxx;"
when i try to connect locally from PC#1 it work good:
SERVER=localhost;DATABASE = my_test; UID = root; PASSWORD = xxxx;"
when i try
i did make my root user remote enabled like that:
GRANT ALL ON *.* to '%'#'%' WITH GRANT OPTION;
and all i get is an Event viewer: unable to connect to any of the specified MySQL host
If both MySql installation are similar (no port changes etc.) then you might want to check connection restriction to the port that MySQL is listening to (usually 3306) on the remote machine. A firewall or something of that sort may be preventing access.
Also if I may ask, have you used any other tool(like MySQL WorkBench or similar) to connect to the MySQL on the remote machine, from the machine which is running your c# form.
That may give you an idea as to whether it access restrictions.
Lastly, i suggest you specify the port in the connection string.
"Data Source =SomeName; Database=SomeDb; User Id=SomeUserId; Password=SomePassword; Port=3306;"

How can connect MySql Online Database to C# desktop application

I am creating desktop application in c# but i wont to use Online Database created in mysql.
String mysqlConnectionString = "Server=216.14.120.105;Database=xxx_keys;UID=xxx_root;Password=xxx;Port=3306";
MySqlConnection connection = new MySqlConnection(mysqlConnectionString);
connection.Open();
this is the code i am using but i got an error unable to access host.
where i am wrong and if you have any proper code or details then give me.
If this is a MySQL database in local server user "localhost" for server IP as georgi-it also told. But if this is an external database first try to open a telnet connection on dos-prompt to see if there is some firewall block or something like that:
telnet 216.14.120.105 3306
if you don't get an error message and see a blank page then it means you can reach mysql server

Data source for connection string

What connection string should I use if SSMS connects to it using simply machine name, without instance name?
I mean it connects using the following string: PCName
I used to connect using PCName/SQLExpress. I cannot set correct connection string in my app in order to connect app to database on this machine.
How can I check what data source I should use? I've checked in Sql Server configuration that server instance named as SQLEXPRESS.
So I tried data source as:
.\SQLEXPRESS
PCName\SQLEXPRESS
.
I'm trying to connect to a service-based database, located in my app folder. So I'm using the following connection string:
data source=PCName;attachdbfilename=|DataDirectory|\spareparts.mdf;integrated security=true;user instance=true;multipleactiveresultsets=true;App=EntityFramework;
If SSMS connects via PCName then your application should be able to use Data Source=PCName. However it depends on whether your application is on the same machine as SSMS or not. If on a different machine it might not be able to connect for a variety of reasons. We can't speculate what the problem might be if all you do to describe the issue is "It won't connect" - what does that mean? Do you get an error message? If so, what is it? Make sure:
SQL Browser service is started
TCP/IP is enabled
Add Network=DBMSSOCN; to the connection string
You've also tried the IP address in addition to PCName
Firewall isn't blocking the SQL Server port

Categories

Resources