无数据库名称的MySQL的ConnectionString建立在C#中的数据库 [英] MySql ConnectionString without Database name to create a database in c#

查看:1305
本文介绍了无数据库名称的MySQL的ConnectionString建立在C#中的数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个情况我确实需要通过使用获得到MySQL所需的连接字符串创建一个数据库到MySQL server.Till我现在已经用于数据库的名字。所以在这种情况下的ConnectionString会是怎样的结构的ConnectionString执行我创建数据库查询到MySQL服务器。

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.

我需要的ConnectionString本地主机。

I need the Connectionstring for localhost ..

请帮忙我..

推荐答案

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

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

这篇关于无数据库名称的MySQL的ConnectionString建立在C#中的数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆