配置字符串的 winforms 连接属性对话框

发布于 2024-08-20 00:40:11 字数 317 浏览 4 评论 0原文

有没有办法在运行时显示用于连接字符串浏览(针对数据库)的连接属性对话框?

因为我希望用户能够使用 GUI 连接到各种数据库。 与我们在 Visual Studio 连接属性对话框中获得的相同。

提前致谢

“http://www.freeimagehosting.net/uploads/c59e853019.jpg"

Is there a way to display the connection properties dialog for connection string browsing(for database) in run time?

As I want the user to be able to connect to various database using the GUI.
The same one as we get in visual studio connection properties dialog.

Thanks in Advance

http://www.freeimagehosting.net/uploads/c59e853019.jpg

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

如何视而不见 2024-08-27 00:40:11

查找这篇文章解释正是您在寻找什么。她的说法如下:

  1. 您需要为您的项目添加一些引用:

    • OLE DB 服务组件 1.0 类型库
    • Microsoft ActiveX 数据对象 2.x 库
  2. 使用以下代码:

    使用 MSDASC;
    使用 ADODB;
    
    私有字符串 BuildConnectionString()
    {
         字符串 strConnString = "";
         对象_con = null;
         MSDASC.DataLinks _link = new MSDASC.DataLinks();
         _con = _link.PromptNew();
         if (_con == null) 返回 string.Empty;
         strConnString = ((ADODB.Connection)_con).ConnectionString;
         返回 strConnString;
    }
    

Look for this article explaining exactly what are you looking for. What she say is the following:

  1. You will need to add a couple references to your project:

    • OLE DB Service Component 1.0 Type Library
    • Microsoft ActiveX Data Objects 2.x Library
  2. Use the following code:

    using MSDASC;
    using ADODB;
    
    private string BuildConnectionString()
    {
         string strConnString = "";
         object _con = null;
         MSDASC.DataLinks _link = new MSDASC.DataLinks();
         _con = _link.PromptNew();
         if (_con == null) return string.Empty;
         strConnString = ((ADODB.Connection)_con).ConnectionString;
         return strConnString;
    }
    
熊抱啵儿 2024-08-27 00:40:11

我一直在寻找这个,看来微软已经发布了 Visual Studio 连接对话框的源代码,以便它可以在 VS 之外使用:

我刚刚尝试过,它工作正常:)

更新 7/2019

自 Microsoft 代码该网站是黑暗的,并且似乎没有关于数据连接对话框的 Microsoft 官方帖子,这里有一个包含 Microsoft 代码的 Github 用户存储库的链接。

https://github.com/kjbartel/ConnectionDialog

原始但现已失效的链接 http://code.msdn.microsoft.com/Connection

I was looking for exactly that, and it appears that Microsoft has published the source for the Visual Studio connection dialog, so that it can be used outside VS :

I just tried it, it works fine :)

Update 7/2019

Since the Microsoft Code site is dark, and there doesn't seem to be an official Microsoft posting for Data Connection Dialog, here is a link to a Github user repository with the Microsoft code.

https://github.com/kjbartel/ConnectionDialog

Original but now dead link http://code.msdn.microsoft.com/Connection

予囚 2024-08-27 00:40:11

我不知道是否存在“预定义”表单,但是,您当然可以创建自己的表单,并使用 DbConnectionStringBuilder 类 (SqlConnectionStringBuilder, OracleConnectionStringBuilderOleDbConnectionStringBuilder),根据用户在自定义创建的表单上输入的参数创建连接字符串。

I don't know if there exists a 'predefined' form for it, but, you could offcourse create your own form, and use one the DbConnectionStringBuilder classes (SqlConnectionStringBuilder, OracleConnectionStringBuilder, OleDbConnectionStringBuilder) to create the connectionstring from the parameters the user entered on your custom created form.

蓬勃野心 2024-08-27 00:40:11

您还可以使用通用数据链接文件

http:// msdn.microsoft.com/en-us/library/e38h511e%28VS.71%29.aspx

使用 XP,但我从未在 Vista 或 7 中尝试过

You can also use Universal Data Link Files

http://msdn.microsoft.com/en-us/library/e38h511e%28VS.71%29.aspx

Work with XP but I never tried it in Vista or Seven

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文