是否可以在C#中使用.mylogin.cnf文件建立连接? [英] Is it possible to use .mylogin.cnf file in c# to establish connection?

查看:143
本文介绍了是否可以在C#中使用.mylogin.cnf文件建立连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#连接器和MySQL方面,我是新手,所以请多多包涵。

I am a newbie when it comes to C# connector and MySQL, so please bear with me.

如果C / C ++应用程序使用.mylogin.cnf文件连接到MySQL服务器,我们可以在C#中使用同一文件吗?如何使用?

If C/C++ application uses .mylogin.cnf file to connect to MySQL server, can we use the same file in C#, and how?

我确实在搜索使用C#时是否可以使用相同的文件连接服务器,但找不到方法。

I did search if it is possible to use the same file to connect to server when using C#, but could not find the way.

如果有人可以告诉我这是否可行以及如何做到(简短示例或带有示例的站点链接将非常有用),我将不胜感激。如果不可能,那么完成功能上相似的连接方式的最佳方法是什么?自定义插件?我们使用社区服务器。

I would really appreciate if somebody could let me know if this is possible and how (short example or a link to a site with an example would be great). If it is not possible then what would be the best way to accomplish functionally similar way of connecting? Custom plugin? We use Community Server.

谢谢。

推荐答案

不能使用<$ .NET连接器库中的c $ c> .mylogin.cnf 。在.NET中,连接选项始终在传递给 MySqlConnection 的连接字符串中指定。

It is not possible to use .mylogin.cnf from the .NET Connector library. In .NET, the connection options are always specified in a "connection string" passed to MySqlConnection.

.mylogin.cnf 中的设置是用以下创建的:

If the settings in .mylogin.cnf were created with:

mysql_config_editor set --host=HostName --port=1234 \
  --user=UserName --password=Passw0rd

则等效的C#代码为:

new MySqlConnection("Server=HostName;Port=1234;UserID=UserName;Password=Passw0rd")

或:

var csb = new MySqlConnectionStringBuilder
{
    Server = "HostName",
    Port = 1234u,
    UserID = "UserName",
    Password = "Passw0rd",
};
var connection = new MySqlConnection(csb.ConnectionString);

这篇关于是否可以在C#中使用.mylogin.cnf文件建立连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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