通用数据链接(UDL)的用法

偶然看到UDL,决定看一下其用法。

UDL:通用数据链接。此文件中提供 OleDbConnection 的连接信息。也就是说UDL只能在OleDbConnection中使用。

 

微软不建议使用UDL

    因为UDL 文件未加密,会以明文形式公开连接字符串信息。因为 UDL 文件对您的应用程序来说是一个基于文件的外部资源,所以无法使用 .NET Framework 保护该文件。

 

用法:   

    在桌面上建一个名为conn的txt文本文件,然后将后缀名改为udl 。双击它,打开相应连接界面,根据界面提示配置连接信息。这里选择的是Oralce。

    配置成功后UDL内容为:

[oledb] ; Everything after this line is an OLE DB initstring Provider=OraOLEDB.Oracle.1;Password=gsc;Persist Security Info=True;User ID=gsc;Data Source=NDEV

 

代码中使用此UDL时,ConnectionString 需要为“File Name =”+UDL地址。

private void GetData()
        {
            using (OleDbConnection oleconn = new OleDbConnection())
            {
                oleconn.ConnectionString = @"File Name =" + Server.MapPath("conn.udl");
                OleDbCommand olecommand = new OleDbCommand();
                olecommand.Connection = oleconn;
                olecommand.CommandText = "select * from CUSTOMIZATION";
                oleconn.Open();
                OleDbDataAdapter oleadapter = new OleDbDataAdapter();
                oleadapter.SelectCommand = olecommand;
                DataSet ds = new DataSet();
                oleadapter.Fill(ds);
            }
        }

 

posted @ 2015-08-31 14:27  iDEAAM  阅读(1443)  评论(0编辑  收藏  举报