I can not open a new connection through my code to my digitalocean server.. It's my first account and will be my first online database program.. here's what I did
after creating an account on digitalocean I've created a droplet and installed LAMP and secure phpmyadmin by following the installation tutorials..
I've given an IPv4 Address: xx.xxx.xx.xxx
when I typein xx.xxx.xx.xxx/phpmyadmin to my browser it asks for username and password, than comes the phpmyadmin screen which asks for username root and it's password
I've created a new database= TestApp and users table..
and then I made a very basic program via c#, I have a textbox and a button and the code is as follows:
string conString = "Server=xxx.xxx.xxx.xx;Database=TestApp;Uid=root;pwd=_______";
MySqlConnection newCon = new MySqlConnection(conString);
string insertCommand = "INSERT INTO TestApp.users(isim) VALUES (?isim)";
MySqlCommand cmd = new MySqlCommand(insertCommand, newCon);
newCon.Open();
cmd.Parameters.Add("?isim", txtpost.Text);
cmd.ExecuteNonQuery();
newCon.Close();
when I run the program it gives the following error:
An unhandled exception of type 'MySql.Data.MySqlClient.MySqlException' occurred in MySql.Data.dll
Additional information: Unable to connect to any of the specified MySQL hosts.
how do I solve my issue?
I don't know DigitalOcean, but I am assuming that the virual server has been configured to only allow web traffic into it (i.e. ports 80 and 443, which is why phpmyadmin works).
Your C# code (is it's not on the server itself) will need to access the MySQL port which by default is 3306. You will need to find instructions on DigitalOcean for opening this up.
Related
I have this code snippet where I am trying to make a connection with a remote database, located on LAN Ip with wamp.
string myConnectionString = "server=192.9.210.62;port=8088;database=testDB;uid=root;pwd=;";
MySqlConnection con = new MySqlConnection(myConnectionString);
con.Open();
MessageBox.Show("connection open");
con.Close();
But it is failing due to socket exception. here are the error
MySql.Data.MySqlClient.MySqlException: 'Reading from the stream has
failed.'
Then, I search for this problem, and it seems that I have to allow a remote connection to my SQL. But remember I have already put my server online already. There is also bind-address setting that need to be set 0.0.0.0 but i am unable to find it in .ini file.
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.
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.
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
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