且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无数据库名称的MySQL的ConnectionString建立在C#中的数据库

更新时间:2023-02-02 21:40:13

您可以选择省略连接数据库参数串。 。这样做,你到了数据库服务器的连接,但你没有连接到任何特定的数据库

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.

从MySQL文档实例

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.

示例

select * from so.tbl_so_q23676633;

在上面的例子中,'所以'是表的数据库预选赛'tbl_so_q23676633

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