【问题标题】:How to use .udl file in app.config file如何在 app.config 文件中使用 .udl 文件
【发布时间】:2013-09-24 14:08:58
【问题描述】:

我的桌面上有 string.udl 文件。其中包含

[oledb] ;此行之后的所有内容都是 OLE DB 初始化字符串 Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=dbVisitorManagement;Data Source=SHREE-PC 所以我必须使用这个文件在我的项目的 App.config 文件中建立连接,那么我需要做什么呢??

【问题讨论】:

标签: c#


【解决方案1】:

我猜你想连接到 SQLOLEDB 的 ans Sqlserver 原因。

在这种情况下,您必须从文件中删除“提供者”

F.E:

                string path = @"C:\YourFileName.udl";
                if(System.IO.File.Exists(path))
                {
                    string testfile = string.Empty;
                    try
                    {
                        testfile = File.ReadLines(path).Last();
                    }
                    catch
                    {
                        // File is empty, handle exception
                    }
                    if (testfile != string.Empty)
                    {
                        var finalPath = tempfile.Remove(0, tempfile.IndexOf(';') + 1);
                        ConnectionString = finalPath;
           // Save ConnectionString to your App.config or do something else with it
                }

另请注意,*.udl 是除本地网络外的一个坏部分,因为每个人都可以看到连接详细信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-12-22
    • 1970-01-01
    • 2017-07-14
    • 2010-10-22
    • 1970-01-01
    • 1970-01-01
    • 2012-10-26
    相关资源
    最近更新 更多