connection to MySql database on host - c#

I have a problem regarding connecting to my database that is located on my website host server. I have watched few tutorials, took a look on few articles here on stack overflow and read official mysql documentation, and i steel can't connect to it thru my c# console app. This is my code:
string connstring = string.Format("Server=www.vm-consult.com; Database=vmconsul_sitedatabase; Uid=vmconsul_mijovicpetar; Pwd=mypassword");
MySqlConnection connection = new MySqlConnection();
connection.ConnectionString = connstring;
connection.Open();
I have also went to c panel in remote MySQL tab and set "%" to my remote sql hosts.
All the parameters for con string are correct. In server in connection string I also tried to set IP address, did not change anything.
This is exception I get(on the last line: connection.open()):
Unable to connect to any of the specified MySQL hosts.
Any suggestions appreciated. Thanks.

Check connectivity with
telnet www.vm-consult.com 3306

I needed to contact my host provider to enable external connection to the database. Thanks everybody.

Related

c# mysql connect mistake

MySqlConnection con = new MySqlConnection("SERVER=http://185.106.208.... ;DATABASE=netcom_demo;UID=root;PASSWORD=test123;");
ı take "unable connect to any of the specified MySql Host"
what can ı do?
The First thing you should do is to check connectivity to the database you can use a tool like Workbench to connect to the database. Also check you can ping the IP address, If you can't connect using a client like Workbench maybe the problem could be a firewall.
This Will help you.
MySqlConnection con = new MySqlConnection("User ID=root;pwd=test123;Initial Catalog=netcom_demo;Data Source=185.106.208....;");

OleDBConnection error Database Server Not Found C#

I'm trying to connect to a remote SQL Anywhere 10 database server using the following connection string but receiving a "Database Server Not Found" error.
OleDbConnection conn = new OleDbConnection("Provider=SAOLEDB.10;ENG=dental;DBN=dentserv;
LINKS=tcpip(host=192.168.1.100,PORT=2638);
Integrated Security = True; User ID = dba; PWD = sql");
Using the same code, I can connect to a local database that is setup the same way as the remote server I'm attempting to connect to without any issue:
OleDbConnection conn = new OleDbConnection("Provider=SAOLEDB.10;Data Source = dental;
Database=dental;Integrated Security = True; User ID = dba; PWD = sql");
I've added and removed multiple variables within the string to troubleshoot to see if there was anything missing (ENG instead of Data Source, with and without DBN, DSN, etc.), most seem to be interchangeable but always throwing the same error of no server.
For some additional information, I am able to connect to this server database using a different database management tool using the same port IP credentials with no issue. It's Database URL is: jdbc:sybase:Tds:192.168.1.100:2638?ServiceName=
Connection String:
DBN=DENTSERV;DSN=DENTAL;UID=DBA;PWD=SQL
Any thoughts? I've been working on this for awhile with no further progress. Any insight will be much appreciated!
The host (host=192.168.1.100); appears to be a private IP (IP for your local network), you cant use that for remote access you may use a Public IP also the server need to be configured for remote access.

Can't connect to SQL Server Express via IP address - c#

I moved from SQL Server 2014 to SQL Server Express (free version) and since then I can't connect to database using SqlConnection with IP.
I can connect local with connection string but when I am using an ip address I get error number 10061, I checked whole net about that error and verified all the issues mentioned: remote connection is allowed, I added port in firewall, enabled tcp in server...
In official version of SQL Server it works fine, but when I moved to EXPRESS free version I can't successfully connect remotely any more.
This is the connection string I use:
SqlConnection cn = new SqlConnection(#"user id = ***; password=***;server=192.168.1.102,1433; Trusted_Connection=no; database=myDatabase; connection timeout=30");
Getting exception error number 10061.
But when I use the local connection string:
SqlConnection cn = new SqlConnection(#"server=ASUS\SQLEXPRESS ;database=myDatabase;user id = ***; password=***;");
That works fine...
What can the problem be?
You still need to specify the instance name when switching to using the I.P to connect.
SqlConnection cn = new SqlConnection(#"user id = ***;
password=***;
server=192.168.1.102\SQLEXPRESS;
Trusted_Connection=no;
database=myDatabase; connection timeout=30");
I should have set the port and ip in server configuration manager.

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

Can't connect to SQL Server 2005 Express from an ASP.NET C# page

I have an MS SQL Server 2005 Express running on a VPS.
I'm using pymssql in Python to connect to my server with the following code:
conn = pymssql.connect(host='host:port', user='me', password='pwd', database='db')
and it works perfectly.
When I try to connect to the server from an ASP.NET C# page with the following code:
SqlConnection myConnection = new SqlConnection("Data Source=host,port;Network Library=DBMSSOCN; Initial Catalog=db;User ID=me;Password=pwd;");
myConnection.Open();
When I run the ASP.NET page I get the following exception at myConnection.Open();:
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 0 - A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.)
I tried restarting the SQL Server but I had no luck.
Can anyone point me out to what I'm missing here?
Thanks!
Let's say your host is localhost. When you are using SQLEXPRESS you need to specify that in your Instance Name.
Loke this: Data Source=localhost\SQLEXPRESS if it is bound to localhost. Otherwise it might just work with: Data Source=.\SQLEXPRESS.
If you have management studio installed you can fire that up and check what connection string it is using!
Still doesn't work..
I'm able to connect to the remote server with SQL Management Studio.
I enter host,port\SQLEXPRESS (of course I my actual IP number as the host and my actual port) in the Server Name field, select SQL Security and enter my username and password and it works perfectly.
When I try to connect from the ASP.NET page, it just doesn't work - I get the error aforementioned. Can it have something to do with the company hosting my asp.net page? (GoDaddy)
here is the code again..(assuming my host is 11.22.33.44 and my db is named bla
string connectString = #"Data Source=11.22.33.44,1433\SQLEXPRESS;Network Library=DBMSSOCN;Initial Catalog=bla;User ID=username;Password=pwd;";
SqlConnection myConnection = new SqlConnection(connectString);
myConnection.Open();
Thanks again

Categories

Resources