有没有一个标准的对话框来构建一个ADO.Net连接字符串(即可再发行)? [英] Is there a standard dialog for constructing an ADO.Net connection string (that is redistributable)?

查看:135
本文介绍了有没有一个标准的对话框来构建一个ADO.Net连接字符串(即可再发行)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用标准对话框来征求ADO.net连接字符串的用户输入。对于这样描述的oledb连接字符串来说,这很简单:

I want to use a standard dialog to solicit user input of an ADO.net connection string. It is trivial to do for the oledb connection string as described here: MSDN Article on MSDASC.DataLinks().Prompt

来自VS的.ConnectionUI.Dialog.dll( HOWTO:使用Visual Studio的选择数据源对话框2005从你自己的代码)。

I've also found examples that use Microsoft.Data.ConnectionUI.dll and MicrosoftData.ConnectionUI.Dialog.dll from VS (HOWTO: Using the Choose Data Source dialog of Visual Studio 2005 from your own code).

不幸的是,这些DLL没有许可重新分发。

Unfortunately these DLLs are not licensed for redistribution.

有没有一个标准的对话框来选择一个数据源可以与我的应用程序分发?

Is there a standard dialog for choosing a data source that can be distributed with my application?

推荐答案

这些DLL的源代码现在可用: http:/ /blogs.msdn.com/b/vsdata/archive/2010/02/02/data-connection-dialog-source-code-is-released-on-code-gallery.aspx

The source code for these DLLs is now available: http://blogs.msdn.com/b/vsdata/archive/2010/02/02/data-connection-dialog-source-code-is-released-on-code-gallery.aspx

此外,您可以使用DataLink属性以编程方式执行此操作:

Also you can do this programmatically using the DataLink Properties:

添加对ADODB.DLL的引用(来自.NET参考)和Microsoft OLE DB服务组件1.0类型库从Visual Studio参考选项卡中的COM选项卡。

using ADODB;
using Microsoft.Win32;
public partial class ConnectionStringStep : Form
    {
        private const string MSSQL_PROVIDER = "Provider=SQLOLEDB.1";

        private const string ORACLE_PROVIDER = "Provider=MSDAORA.1";

        private const string MSSQL = "MSSQL";

        public ConnectionStringStep()
        {
            InitializeComponent();
        }


        private static string DataBaseType()
        {
            //get the data from some previous screen or some kind of storage
            return MyStorage.GetProperty("DATABASE_TYPE") ?? "MSSQL";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            var dataBaseType = DataBaseType();

            var adodbConnection = new Connection
                                      {
                                          ConnectionString = dataBaseType == MSSQL ? MSSQL_PROVIDER : ORACLE_PROVIDER
                                      };

            object connection = (object) adodbConnection;

            var dialog = new MSDASC.DataLinks();

            dialog.PromptEdit(ref connection);

            connectionTextBox.Text = adodbConnection.ConnectionString;
        }
    }

zueintel.com/2011/07/20/building-an-installer-and-displaying-data-link-properties-dialog-box-for-connection-string/rel =nofollow

DataLink Properties Reference

这篇关于有没有一个标准的对话框来构建一个ADO.Net连接字符串(即可再发行)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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