Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have got a situation where i do need to create a database into MYSQL by using the connection string needed to get into mysql server.Till Now i have used connectionstring with database names .So in this situation what will be the connectionstring structure to execute my create database queries into mysql server.

I need the Connectionstring for localhost ..

Please help me ..

share|improve this question
    
@SonerGönül How can i open connection with mysql server without specifying database name in Connectionstring –  user3617097 15 hours ago
    
mysql provides some default databases like mysql, information_schema.. try with any on of the db name –  Ganesh 15 hours ago
add comment

2 Answers

up vote 1 down vote accepted

You can optionally omit the database parameter in connection string. Doing so, you get a connection to the database server but you are not connected to any specific database.

Part of Example from MySQL documentation:

MySql.Data.MySqlClient.MySqlConnection conn;
string myConnectionString;

//myConnectionString = "server=localhost;uid=root;pwd=12345;database=test;";
myConnectionString = "server=localhost;uid=root;pwd=12345;";

try
{
    conn = new MySql.Data.MySqlClient.MySqlConnection();
    conn.ConnectionString = myConnectionString;
    conn.Open();
}
catch (MySql.Data.MySqlClient.MySqlException ex)
{
    MessageBox.Show(ex.Message);
}

But you have to use database name to qualify the table or other object names within your queries.

Example:

select * from so.tbl_so_q23676633;

In the above example, 'so' is the database qualifier for table 'tbl_so_q23676633'.

share|improve this answer
add comment

Using OleDb you can achieve this. // OleDb

    using System.Data.OleDb;
    OleDbConnection conn = new OleDbConnection(); 
    conn.ConnectionString = "Provider=MySqlProv; Data Source=ServerName; User id=UserName; Password=Secret";
    conn.Open(); 

For more info MySQL Connection string without database Another Useful link Types of MySQL connection strings

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.