I'm developing an app with C# and I need to access MySql database in my university server. They provided me one login and password. With they, I can access the MySql via PhpMyAdmin, but when I try to connect with my app, the following error occurs:
"Unable to connect to any of the specified MySQL hosts."
I thought that could be the privileges of the user. But I'm not sure. So, what could be? With the possible solutions I can ask them to correct.
My connection code:
server = "server";
database = "database";
uid = "id";
password = "pass";
connectionString = "SERVER=" + server + ";" + "DATABASE=" + database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";
conn = new MySqlConnection(connectionString);
conn.Open();
Thanks a lot! I'm sorry for my bad English. =(
Mysql server's default port is 3306. You need to add a connectionstring in web.config and use them all over in your web-app.
As Meda written in her answer you need to use localhost or 127.0.0.1 it must be the ip of your server where you actually host your mysql database. remember that remote access must be enabled (on your university server) if you provide the IP to access the mysql database.
Tried these thing will surely fix your issue.
I use MySQL with my C# projects and I define the host value as:
localhost or 127.0.0.1
an IP address (xxx.xxx.xxx.xxx)
a host url (my.dbserver.com)
here is a working MySQL connection string:
<add name="connectionString"
connectionString="server=xx.xx.xx.xx;database=yyyyy;
User Id=zzzzzz;Password=**********;"
providerName="MySql.Data.MySqlClient" />
Related
i am developing an app where i am having a common sql server database .mdf put on a LAN Server which is needed to be connected to two or more different instances of a same application as other stations.
i am able to select the database but it is giving me and error posted below:
how to overcome this? the connection string is
connectionString = #"Data Source =(LocalDB)\MSSQLLocalDB; AttachDbFilename = " + path + "; Integrated Security = True; Connect Timeout = 30";
P.S. it is working when a single instance is connected to it and it is preventing the second or third app to use it.
any help will be appreciated.
You need to host the database on a network server. Several clients can connect to a SQL Server. But several clients cannot simultaneously connect directly to an MDF file.
The file alone cannot handle the concurrency. You need to have an application for it. That's where SQL Server comes into play.
After hosting, you need to change your connection string as well. Then it should work.
connectionString="Data Source=ServerName;Initial Catalog=DatabaseName;Integrated Security=True;MultipleActiveResultSets=True"
I'm building a winform application with C# lang and MySQL database. There's 3 computer to work with.
1st computer connected with LAN network (Static ip address), it creates hotspot with connect*fy app, and MySQL database server
2nd computer connect to 1st computer with WirelessLAN, connect to its connect*fy app
3rd computer connect to 1st computer with LAN cable (static IP address)
I can only connect 1st and 2nd computer. When I try with 3rd computer it showing message "Unable to connect any specified MySQL host"
Connection Strings that I used
string user = "koas";
string password = "poipoi";
string database = "bke_nota_db";
string host = "10.20.10.129";
MySqlConnection conn = new MySqlConnection("server=" + host +
";database=" + database +
";username=" + user +
";password=" + password +
";port = 3306" +
";");
Server's IP address that I used is 1st computer static IP adress that connect to LAN.
What should I do?
My MySQL connect code below is 'Catching' this error: "Unable to connect to any of the specified MySQL hosts."
My DB is on my linux website and I have remote access enabled using % so anyone can access the DB.
My code is .NET C# and I have a winform.
string server = "http://www.mywebite.net";
string database = "mywebsite_app";
string uid = "admin";
string password = "Password";
string connectionString;
connectionString = "SERVER=" + server + ";" + "DATABASE=" +
database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";
MySqlConnection dbConn;
try
{
dbConn = new MySqlConnection(connectionString);
dbConn.Open();
if (dbConn.State.ToString() != "Open")
{
this.Text = "could not open database connection";
}
else
{
this.Text = "database connection opened";
}
}
catch (Exception ex) // catch on general exceptions, not specific
{
this.Text = ex.Message;
}
Thanks for any help...
If you mysql database is on remote hosting, then you usually out of luck try to connect to that database remotely.
The hosting provider usually blocked remote mysql access.
Try using ssh-tunneling.
download putty
http://www.chiark.greenend.org.uk/~sgtatham/putty/
open the command line, and execute putty from the installation directory
putty username#remote_mysqlhost -L 3306:localhost:3306
or you could use the gui, fill the address with your mysql remote, but dont open connection yet.
go to ssh tunnel, add new forwarded port 3306, and the destination as localhost:3306.
as of why the destination is localhost, it is because the destination is what the ssh session see. because you already connected to your remote server in your ssh session, thus, the mysql host is local.
this could also be a set up for dmz.
you can create a dmz gateway using putty to tunnel trough any computer within the dmz network. but the computer behind the gateway, wont publicly expose to the internet.
dont forget to klik the add button to make sure the configuration is added to tunnel list.
open the connection and use your password (ssh user and password, usually the same as webhosting control panel user and password
Now, instead connecting to your remote mysql, you can connect to mysql trough localhost. it would be tunneled by putty to your remote mysql.
try to connect using mysql administration tool first. to test wheter or not the connection is success.
the way ssh tunnel work is almost the same as vpn, from user view.
but without the hassle of setting up vpn server on remote host.
This is my first time connecting to SQL Server via C#, apologies in advance.
I'm trying to connect to my SQL Server to get some information. The code I'm using is:
SqlConnection myConnection = new SqlConnection("server=server;" +
"Trusted_Connection=yes;" +
"database=DB; " +
"connection timeout=30;"+
"User ID=SQLUser;" + "Password= SQLPass;");
myConnection.Open();
However, when I try to connect, I get the error:
Login failed for user 'Company\Personal ID'.
These are not the credentials I intended to use (sqluser & sqlpass). If anyone knows where I'm going wrong, I'd appreciate it.
Simply get rid of Trusted_Connection=yes;. It's ignoring the User ID and Password parameters because you're telling it to use your domain credentials.
Now, the error itself is saying that your domain user doesn't have a Login to the SQL Server.
how can i connect win nt sqlexpress?
i am using this code to connect.it works with any version and kind of sql.
internal string GetConnectionString()
{
return "Data Source=" + "MyPC\SQLExpress" +
";Initial Catalog=Master;User ID=" + username +
";Password=" + password;
}
when connectiong with express ===>>>
Login failed for user 'NT AUTHORITY'. The user is not associated with a trusted SQL Server connection.
or
Login failed for user 'sa'. The user is not associated with a trusted SQL Server connection.
or
Login failed for user 'sysadmin'. The user is not associated with a trusted SQL Server connection.
You need to add the following to the connection string:
Trusted_Connection=yes;
If you are trying to use windows credentials you will need to set:
Integrated Security=true;
This will use Windows authentication rather than SQL authentication. If you don't spesify a user name and password, the currently logged in user will be used implicitly.
See http://www.connectionstrings.com/sql-server-2005 for more details.