how to connect c# windows form with remote mysql database - c#

I want to connect my server pc MySQL database with client pcs. I make configurations in xampp server. PHPMyAdmin shares with fine in other client pcs. but I run my c# form it gets connection name error. this is my connectiondb class in c# form.
public static MySqlConnection conString()
{
MySqlConnection conn = new MySqlConnection(#"server=http://192.168.8.102; userid=root; password=0713; database=pos_system; port=3306");
return conn;
}
I try to run my application using a client pc but it shows this name cannot find. how to fix my error. I also open firewall port 3306.

Your connection string format is not correct for MySql, try something like this:
var con = new MySqlConnection(#"Server=192.168.8.102;Port=3306;Database=pos_system;Uid=root;Pwd=0713;");
For more information check:
https://www.connectionstrings.com/mysql/

Related

how to deploy winform app with mdf file on server

I have a winform app with a database running on sql server 2012. I want the app to work on multiple computers connected to a server in the local network.
I deployed the app using clickonce and moved the mdf file to the server.
Then I installed the app in a few computers and it works on every one of them separately however when the app runs on one computer and I try to open it on another one I get the following exception:
Cannot open database (database name) requested by the login. The login failed.\r\nLogin failed for user 'USER-PC\user'
using (SqlConnection con = new SqlConnection(conString))
using (SqlCommand command = new SqlCommand("select 1", con))
{
con.Open(); //exception thrown here
object returnValue = command.ExecuteScalar();
if (returnValue != null)
returnString = returnValue.ToString();
con.Close();
}
The connection string is:
Data Source=(LocalDB)\v11.0; AttachDbFilename=path on server\database
name; Integrated Security=true;
I have tried to change attachdbfilename to Initial Catalog=database name, and add users to the db in ssms and add user id and password to the connection string. Nothing helped.
I'm afraid I have some basic concept misunderstood and doing it the wrong way.
How can I resolve this problem?
Please check/correct broken links between Login and DB-User with sp_change_users_login.

Saving to database from WinForm

I'm having trouble to save details about a movie in my database. I know the name giving is not good, but I have just made 1 textbox for input right now, as I am getting desperate. Can anyone tell me what I have done wrong in my code.
If it helps I having the following error which suggests that it can't connect to my localDB but I am not sure.
Error from code :
Code:
private void btnRes_Click(object sender, EventArgs e)
{
SqlConnection sc = new SqlConnection();
sc.ConnectionString = ("Data Source=localhost;Initial Catalog=LoginScreen;Integrated Security=True");
SqlCommand com = new SqlCommand();
sc.Open();
com.Connection = sc;
com.CommandText = ("INSERT into movieTable (movieID, movieName, movieLength, movieDescription) VALUES ('"+textBox1.Text+"','"+textBox2.Text+"','"+textBox3.Text+"');");
com.ExecuteNonQuery();
sc.Close();
Your local database is not accessible over network. Try the following -
Check whether server is on
Check whether firewall is not blocking the Program
Check whether Named Pipes and TCP/IP is enabled in SQL Configuration manager. To access SQL Configuration Manager, go to Start > SQL Server (Version) > SQL Configuration Manager. Then expand Client Configuration (if it's x64 then there will be 2 item , click that does not have 32 with it).
From the right pane select Named Pipe, Vias and TCP/IP and enable all and restart server.
Make sure you are using correct instance name. MQL Server Enterprise or Standard editions might not have instance names but also can be installed with instance name. See in you SQL configuration manager that you are using the proper instance name.
Then try again.
First of All check the Authentication mode of the Sql Server whether it is in Windows Authentication Mode or SQL Server Authentication Mode
Secondly Check whether the service of the SQL Server is in running state or not
If the SQl Server installation mode is SQl Server Authentication Mode then the connection string used is :
Server=myServerName\myInstanceName;Database=myDataBase;User Id=myUsername;
Password=myPassword;
If the SQL Server installation mode is Windows Authentication then the connection string is :
Initial Catalog=MyDb;Data Source=MyServer;Integrated Security=SSPI;

Unable to connect MySQL hosts with MySQL-Front

I want to connect my web project using vs2010 c# with mysql database using MySql-Front, before this I'm using xampp phpMyadmin and I use this query;
"User Id=root;Server=localhost;Database=myDB"
to connect my database but I can't use it when I tried it with MySql-Front. How can I connect my database with MySql-Front? I've never use MySql-Front before, is there any way to do it? thanks
Sorry I already know how to connect my new database, I only need to know new address for my database, so I only need to change the query;
"Server = myServer; Database = myDB; Uid = myUsername; Pwd = myPassword"

C# Connecting to remote oracle database. ORA-12154 Could not resolve the connect identifier specified

I have written an application which connects to an Oracle 10g database. From one computer it works fine but from another it errors. Neither computer is the database server.
ORA-12154: TNS:could not resolve the connect identifier specified
The connection string used:
private string = "provider=MSDAORA;Data Source=192.168.1.5/MyInstance;User Id=username;Password=password";
private OleDbDataAdapter oda = oda = new OleDbDataAdapter();
private OleDbConnection oracleConnection = new OleDbConnection(conString.ToString());
However the computer where it works is the database server for another oracle instance!
My application needs to be able to connect to the oracle instance from any computer.
Any ideas?
EDIT: Ive tried this What is the exact format of a connection string for Oracle? but couldnt get any of the options to work.
EDIT: I found a connection string that works.
Provider=OraOLEDB.Oracle; Data Source=(DESCRIPTION=(CID=GTU_APP)(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.1.5)(PORT=1521)))(CONNECT_DATA=(SID=MyInstanceID)(SERVER=DEDICATED)));User Id = myusername; Password = mypassword;
Since you can connect trough SqlDeveloper then this supposed to be an issue related to your connection string. I'm not quite sure is there a way to get SqlDeveloper's connection string. Verify your connection string with connectionstrings.com variants.
After alot of playing about the following connection string works for me.
Provider=OraOLEDB.Oracle; Data Source=(DESCRIPTION=(CID=GTU_APP)(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.1.5)(PORT=1521)))(CONNECT_DATA=(SID=MyInstanceID)(SERVER=DEDICATED)));User Id = myusername; Password = mypassword;

SQL connection string for database on network

I want to connect to a database on a host except localhost, my DBMS is SQL Server and I'm using ado.net, like this:
SqlConnection con = new SqlConnection(constr);
con.Open();
SqlCommand cmd = new SqlCommand("insert into st (ID,Name) values ('"+cnt.ToString()+"','havijuri');", con);
//some sql commands.
con.Close();
what should I use as the constr (connection string), and with these information:
host IP: 10.15.10.12
the file is database1.mdf,
in this directory(on the host): D:\Project1\DataBase
Tell me if any other information is needed
If the mdf file is not attached to an instance of sql server and you want to connect to the database while it does not exist on the same machine as your application, you need first to copy the database to the server with the mentioned IP and attach it to an instance of sql server installed on that server.
The connection string in this case -if you have a domain and will be authenticated to the database server by windows authentication- will be as follows:
"data source=10.15.10.12; integrated security=SSPI;initial catalog=database1"
Or you can create a sql server user on the database sever and connect using the following connection string:
"data source=10.15.10.12; initial catalog=database1;user id=<username>;password=<password>"
http://www.connectionstrings.com/sql-server-2008
create a file on your desktop called test.udl open it up and follow the steps to connect to your database then click test to make sure it works. then open the file in notepad, it will be 1 line and contain the connection string
and with these information:
•host IP: 10.15.10.12 •the file is
database1.mdf, •in this directory(on
the host): D:\Project1\DataBase
You can not. Database file attachment is only supported by express, not by the real server. ForSL Server, you need the database name (which can be different than the file name) and the database must e mounted first by the DBA. You also need acces to the server (as in: username, password). The security credentials are - again - determined by the DBA.
So, you miss the critical information (name of the database, username, password) to access a database server.

Categories

Resources