I use MySQL .NET Connector to communicate with the mysql server. And everything is fine if I set the connection string as:
<add key="ConnectionString" value="Server = localhost; Port = 3306; Database = test; Uid = root; Pwd = root;" />
I'm going to use my program to reach the MySQL Server remotely from another location. How will the connection string supposed to be set in this case?
I tried:
... Server = http://localhost; Port = ...
just as experimenting, but didn't work. Thank you.
Server = localhost specifies the name of the server connected to. In this case it refers to localhost a special name which always refers to the local computer regardless what it is actually called.
You can change this value to the NETBIOS name, DNS name or IP address of the server.
Related
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.
I need to connect my C# desktop app on PC 1 with database that exist on SQL server instance at Windows Server 2008. First I cannot make my connection string works.
My connection string is:
Server=(Server_Ip)192.168.1.115\(InstanceName)SQLExpress8;initial
catalog=My_Database;integrated security=True;MultipleActiveResultSets=True;
I also tried:
Server=(ServerName)DATABASE\(InstanceName)SQLExpress8;initial
catalog=My_Database;integrated security=True;MultipleActiveResultSets=True;
But that doesn't work.
By the way I have replaced server with datasource and it still doesn't work.
I am not sure if you are putting the parenthesis in your connection string but this is an example of a working one for sql server
connectionString="Server=testServer\instanceName; uid=readOnlyUser; pwd=1234567; database=testDatabase" providerName="System.Data.SqlClient"
where
testServer = IP or server name
instanceName = instance name, sometimes SQLExpress for sql server express
testDatabase = database name
uid = user name
pwd = password
you CAN connect your windows app to the database, however the server IP has to be public to the internet, you will have to mess with firewall settings in order to do that to allow the IP to be accessed publicly.
With the service running on my machine(Setup on a LAN with no internet connection), I can connect with the following :
string sConnection = #"Server=localhost; Port=3306; Database=some_database; Uid=root; Pwd=genericpassword;";
MySqlConnection cnTest = new MySqlConnection(sConnection);
cnTest.Open();
How should I Modify my connection string to connect from another PC on the lan to my MYSQL server?
*side note : The IP of my local machine is setup to be 192.168.0.1.
What goes after "Server=" is the address of the server.
So if your server is on 192.168.0.1 - it'll look like
string sConnection = #"Server=192.168.0.1; Port=3306; Database=some_database; Uid=root; Pwd=genericpassword;";
Just replace 'localhost' with the address you're given.
That said, it's generally considered to be good procedure to store connection strings in web.config / app.config - whenever you deploy it on some other environment, you won't want to rebuild it. This link might help with that.
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;"
I'm having trouble connecting to a SQL Server on a machine in our LAN.
i have done the following :
1.) Made the IP of the machine running the Server 10.0.0.7 and made the IP of the other machines on the LAN IP 10.0.0.X . There is no internet on the LAN(and it will stay that way), changeing IP is permitted.
2.)Enabled remote connection by doing This
3.)Used the appropriate connection string.
Now my only Question that remains is regards to the connection string of those who wish to connect on the server, here is the current Con-string:
string sConnection = #"Server=10.0.0.7\MARNUS-PC\MARNUS_HOME; User ID=MARNUS-PC\MARNUS_HOME; Password=somepassword; Initial Catalog=TestDB;";
My questions are :
1.)What do i put the Server portion? here is my Server name and instance name acording to
the management studio - Server name : MARNUS-PC\MARNUS_HOME , Instance name : MARNUS_HOME.
2.)What do i use as user ID? I wish to use Windows authentication instead of sql server authentication(i have enabled both on server), so how should the connection string change and how to do i allow a user from the server's side on the management studio(if needed)?
3.)I asume if I use Windows authentication i do not need the password part of the Con-String?
I apologize for all the questions,but i was taught MS Access and is now making the switch to SQL Server by myself.
Your connection string must be something like....
string sConnection = #"Server=MARNUS-PC\InstanceName; User ID=MARNUS-PC\MARNUS_HOME; Password=somepassword; Initial Catalog=TestDB;";
Instance name is the Sql Server Instance name.
If you are not Sure about your instance name execute the following statement in your Sql Server Management Studio
SELECT ##SERVERNAME
It will return the [ServerName\InstanceName] you can pass the whole returned string to your connection string are your Server name Server=ServerName\InstanceName;
Windows Authentication
To use windows authentication you will have to a connection string something like this..
string sConnection = #"Server=MARNUS-PC\InstanceName; Initial Catalog=TestDB; integrated security=SSPI";
The IP address identifies the computer, so you wouldn't use both the IP address and the computer name. You can use the IP address in the server setting:
Server=10.0.0.6\MARNUS_HOME;
or you can use the computer name:
Server=MARNUS-PC\MARNUS_HOME;
You are correct that you shouldn't specify any password when you are using windows authentication, and you shouldn't specify any user name either, but you need to specify that you are using it:
Trusted_Connection=Yes;