Frage

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 ..

War es hilfreich?

Lösung

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'.

Andere Tipps

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

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top