I'm trying to connect to mysql database from C#, but I have no idea how to get the connecttion string, since ubuntu is not like mssql has a visual UI. I have install phpmyadmin on ubuntu server already
it should looks like this
var str="Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword";
var connection = new MySqlConnection(str);
myServerAddress is the Ip of your server
Database is the name of your Databas
Uid is the username of the user that you want to use to authenticate to the database
Related
Im trying to connect to MySQL database on Azure through C#. I am using MySQLConnector package for my program.
I have admin account so I can easily access to the database through Sever Explorer in Visual Studio in SSH Sever Authentication . However I can not do the same with C#. I even tried to copy the exact connection string given by Sever Explorer but I still cant connect to my database through C# . I always get the error "1042: Unable to connect to any of the specified MySQL hosts." . The connection String from Sever Explorer provide necessary param : Data Source, Inital Catalog, Persist Security Info, User ID and Password.
As I have admin account. I have also tried to copy the connection String provided from Azure Portal for ADO.net. The connection String look a bit different . For example it provide extra parameter like
TrustServerCertificate, Encrypt, MultipleActiveResultSets. However if I used this connection string, the program does not compile. Visual Studio tell me the these parameters are not supported . For example :'Option 'MultipleActiveResultSets' not supported.' etc. If I deleted those paratemters, I have the same 1042 error. Please help me, I am new. Thanks
The Connection String from Sever Explorer in Visual Studio look like this:
Data Source= ******.database.windows.net;Initial Catalog=******;Persist Security Info=True;User ID=******;Password=******
The Connection String from Azure Portal look like this:
Server=tcp:******.database.windows.net,1433;Initial Catalog=******;Persist Security Info=False;User ID=******;Password=******;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;
The Connection String from Azure Portal look like this:
Server=tcp:******.database.windows.net,1433;Initial Catalog=******;Persist Security Info=False;User ID=******;Password=******;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;
This is a SQL Server connection string. You cannot use MySqlConnector with this connection string. Are you sure you're using Azure Database for MySQL and copying the connection string from the right database?
I am trying to establish connection between my application in C# and MySQL. I have downloaded .NET connector from MySql website.
I have installed MySQL server with TYPO3 winstaller, and it is running properly.
Here is my code:
MySqlConnection con = new MySqlConnection("Server=localhost:8501;Database=drogy;Uid=root;Pwd=;");
con.Open();
It says that: Unable to connect to any of the specified MySQL hosts.
In PHPMyAdmin I see host as localhost:8501. I am sure that user root has password set to NO and I am also pretty sure about the database name. How can I do this please? Thank you
you should not mention the password if maybe its should be empty means use the ' ' single quotes in you code.
And you should remove the ; in after the password like ot;Pwd=;"); you should change like ot;Pwd=");
if your not add the connector, first of all you should must add the MySQL Connector.
sample code:
"server=localhost:portno; user id=yourusername; password=yourpassword; database=yourdatabasename"
update:1
All had happend after moving database files to new location and after updating mysql server. All tables with InnoDB engine disappeared from my database. I was trying to recreate them, but mysql told me 1146: Table 'xxx' doesn't exist all the time until I had recreated my database and restarted mysql service.
I think there's a need to read about InnoDB table binaries.
click here : 1
*Pwd=;"*Required your database password
In the password field give your password and try it.. it will work
I'm very new to SQL and made a small program where a user can input some data, click submit and the data is then stored in a table in the database.
I know want to move the application onto a friends computer, which i'm assuming has no SQL software installed, what would be the easiest way to do this, when obviously the connection string is unique to my computer and the database is stored on my computer.
You will have to install SQL Server on their machine first and foremost. Once this is done, you can obtain a relevant connection string. Note, for the 'Server name' part of the connection string, if you are using SQL Express, instead of using 'localhost', or the name of the server instance (i.e. 'MyMachine'), you would use 'localhost\SQLEXPRESS'/'MyMachine\SQLEXPRESS'.
After setting up the SQL Server instance on the new machine, to copy the required database, first detach the database to avoid any corruption. Now you are free to merely copy the file from your machine to theirs and go through the usual attachment process using SQL Server Management Studio (SQLMS).
I hope this helps.
You can use SQL CE or other file databases. On this way you need to install SQL CE(you can include SQl CE installer into your program installer) on target computer and after that you can easy copy db-file from you computer to target computer.
Also, you can use relative path to db-file from your exe file instead of fixed connection string:
string dbDirPath=Path.Combine(AppDomain.CurrentDomain.BaseDirectory,"DB" );
private const string CONN_STR_TEMPLATE = "Data Source={0};Persist Security Info=False;";
string dbFilePath = Path.Combine(dbDirPath, "my.sdf");
_connStr =String.Format(CONN_STR_TEMPLATE,dbFilePath);
You cannot simply copy your database since SQL Server database is NOT a standalone database as SQL Compact edition/MS Access.
You may configure your router to remote access SQL Server instance over the Internet by forwarding the port
Accessing SQL Server Instance through NAT
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"
currently i made C#.net application with MYSQL database connectivity. here it runs completely in my pc means in localhost.
But Now i want to move my database on other computer and doing same thing which is working with my localhost....
in short i want to connect my application with Remote MYSQL server
So What should i do????
my connection string is below
string connectionpath = "server=localhost;database=mydb;uid=root;password= admin";
what change i do?
At least a couple of things:
Set up your connection string to reference the server.
e.g.,
string connectionString = "server=10.10.5.100;uid=theuser;password=thepassword;";
And ensure that the user you are using has the correct privileges to be able to log in remotely.
It might be that you cannot log in remotely to certain accounts such as the admin (root) account.
Change
string connectionpath = "server={MyRemoteMachine};database=mydb;uid=root;password= admin";
where {MyRemoteMachine} is the ip or name of the remote server.