Accessing Remote Mysql via c# from local pc - c#

I am working on a winform application on C#. Now i have to access a remote mysql database. Well i have a paid server and added my ip address in remote access ip address list.
But still i am not able to access remote database. I want to know whats the way then, what would be the connection string in C#. Any idea would be helpful.
Thanks in Advance.

Here is a list of connection string settings for MySQL
If they don't work, check your firewall settings, also try via the MySQL command prompt.

Related

C# - Remote Connection to XAMPP-Database via LAN

I have a database hosted with XAMPP on a PC with IP: 10.35.250.195
I want to access this database from a laptop in the same LAN where my C#-Application is running on.
This is my connection-string:
"SERVER=10.35.250.195;DATABASE=testdb;USERID=root;PASSWORD=;"
But I'm being unable to open a connection from a remote pc/laptop.
I can access the database with the above connection-string from the PC where the database is hosted. I can also access the phpmyadmin in the browser from the remote laptop with "10.35.250.195/phpmyadmin". So the connection works from the laptop to the PC with the database, but I am not able to open this remote connection in C#.
Within phpmyadmin I allowed user "root" to access host 10.35.250.195 with all rights and I even allowed that every user can access host 10.35.250.195 with all rights to get sure (I know I should not do this because of security reasons...).
How can I access the database in c# with mysql from a remote PC via Lan? Can somebody help me to find the fault?
Maybe your port of the DB is blocked by a firewall?
MySql has Port: 3306
and you could also try a PC based tool to test it like
https://www.heidisql.com/

Need help in SQL Server Remote Access

how to connect two laptops to share a database using windows form application? i mean i've installed mssql server 2008 in my laptop, i need to make windows form application so my friend can modify the database from his laptop, it's not in LAN , we have to use Internet as medium to connect, it'd be helpful if anyone can show me some directions like how connection strings should be. thanks :)
You should consider looking into this. If you search for Error 40 or Error 26 SQL Server. You will get lot of links for connecting SQL Server remotely both on LAN and WAN.
Take a look at this link as well. Screenshots are added here
There are multiple steps involved
Enable default login (sa) - not a good practice
Enable remote connection on sql server
Enable SqlBrowser service - either through Sql Server configuration manager or type services.msc on Run(Ctrl + R)
Add SqlBrowser.exe to firewall exception
Open TCP port 1433 and add it to firewall
Enable TCP, NamedPipe in Sql Server Configuration manager.
Check your public IP using any site like Seemyip.com
Give this IP to your friend along with sql server instance name
On remote machine - enter IP\ServerName with credentials for sa.
OP you just need a dynamic DNS Record (for free at dyndns.org) and then you can create a port forwarding on your Router/Firewall to your SQL server.
That way your SQL Server will be accessible over the internet. Just update your connection string with the dynamic DNS entry that you registered.
This link would be helpful to set the configuration.The link tells how to manipulate connection string according to scenarios.
Here is your:
Server=myServerName\myInstanceName;Database=myDataBase;User Id=myUsername;
Password=myPassword;

i can't access to mysql database from c#

i have a web site and in it's phpmyadmin create a database and i want to connect to it from c#.
i use MySQL connector for .NET in visual studio 2010.
my String Connection is :
server=158.58.185.197;database=porbarco_base;uid=****;pwd=****;CharSet=utf8;
but i can't connect to database and give an error : Unable to connect to any of the specified MySQL hosts.
How i can connect to this database.
i see many threads in stackoverflow but don't solve my problem.
The likelyhood is that the problem is less your C# and more remote access to MySQL
You need to check the following.
Is MySQL listening a network address. Check your mysql configuration file. Look for an entry for bind address. if its set to 127.0.0.1 then you are just listening on localhost, change it to 0.0.0.0 and remember to restart the service
Is your linux firewall blocking remote access to the mysql port.
Does your mysql allow remote access for the specified user from a remote host. see This link for an example of how to set this up
If you are trying to access it directly using the IP address then the port 3306 needs to be open. Is the port open? If the application is hosted on the same server as the database then I would recommend using localhost to access it instead of the IP address.

mysql remote server access from C# application

I have done a small C# Win Forms application, that connects to mySQL database using mySQLconnector. This works perfectly ok with my localhost.
String ConnectionString = "server=xx.xxx.xx.xxx;uid=myuserid;pwd=mypassword;database=dbname";
But I do get following error when I try to connect to remote server:
Unable to connect to any of the specified MySQL hosts.
{"No connection could be made because the target machine actively refused it xx.xxx.xx.xxx:3306"}
I have pinged the server from command prompt and I get response.
I also verified mySQL server settings in remote server database (correct name/ip, portno:3306, skip networking:OFF)
The remote server is accessible without any problem from web server that runs php script and uses same settings as the connection sting I listed above.
The mySQL server is hosted on external shared hosting company 123reg.co.uk with me logging to phpmyadmin using same uid/passwd as like in connection string.
I can't understand what is different between webserver accessing OK, but my C# app having trouble with it??
Can any one please help...
Thanks in Advance
Sam
I've had issues with servers setup so they won't accept remote connections. This is for security reasons mainly. Some places will let you enable it in the CP, but if you have direct access to the server, you should be able to follow these steps.
http://www.rackspace.com/knowledge_center/article/mysql-connect-to-your-database-remotely
Your ip address will be different from the web server.
If your ip address is static you can grant access to your ip address within your mysql database ( https://www.google.com.au/search?q=mysql+grant+access+to+user+from+host ).
I'd recommend using the server to access the database and make your c# application talk to your webserver using ajax/json calls ( https://www.google.com.au/search?q=C%23+Win+Forms+ajax+json ) - that way you're not tied to an ip address for access.
Alternatively you can look at setting up ssh tunnels to your webserver if remote shell access is available so you can get the same access as your webserver. ( https://www.google.com.au/search?q=ssh+tunnels+example+mysql That's what I do myself)

How to connect MySQL running on a web server from c#?

I am working on an C# application which would use the remote MySQL database located in my website hosted on a Linux server with PHP & MySQL support.
I tried to connect directly to the MySQL database, but was not able to connect due to restrictions at my hoster side.
can somebody help me please, can i do that with this restrictions ?
You need access to port 3306 on the remote machine. You can test if you have access to this port using telnet or similar
telnet ip 3306
These are the solutions you have:
A) Create local dev environment: You don't provide much information. If my guess is correct you are developing locally and later you plan to deploy your c# application to web server, that also will contain mysql db.
Install mysql in your local machine
Get a copy of the DB.
Configure your C# program to connect to your local mysql (localhost:3306)
When you deploy code it to your web server, it will connect also to your "localhost 3306" that will be the mysql installed into the web server.
B) Use VPN to access mysql: If A is not applicable another solution consist in installing some kind of VPN between web server containing mySQL and the pc running your application. Once VPN is setup and you can access port 3306 (by telnet as explained before), then your app will work.
C) Open ports to access mysql: The most easy solution is asking for administrator to open ports for you. 99% of the times the answer will be no, so I will not follow this route. (Maybe there is some kind of solution in your web provider that allows to open specific ports for a given IP, but I doubt it)
You can't. The server needs to have allowed remote connections and if this isn't possible, than you're out of your luck.
But, there may be another way... If you can create a web service on the server you're able to connect from, you should be able to communicate with the data in mysql virtually from anywhere.
You can try to create a way of API, if your server blocks incoming connections from web, just overload MySQL Functions you need to use with PHP and "echo" results as a server, parse them as a client with your c# application, it is the only way to organize such a system, or, you can allow incoming connection to MySQL, then watch on this article on CodeProject

Categories

Resources