相同的连接字符串但密码不同 [英] Same connection string but different password

查看:72
本文介绍了相同的连接字符串但密码不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们,

我在MS Access连接字符串中有问题,我正在读取Access文件,这些访问文件包含密码,每个MS Access文件随机包含一个密码,其中两个密码是随机的,所以我不知道动态是哪个密码,因此基于密码我要更改连接字符串.
任何人都可以引导我.

Hi friends,

I have a problem in MS Access connection string , i am reading Access files , those access files contains password,Each MS Access file contains one passwords from 2 randomnly, so i dont know which will be the password dynamically, so based on the password i want to change the connection string.
any one please guide me.

推荐答案

嘿,

看看 SqlConnectionStringBuilder [ ^ ].
Hey there,

Take a look at SqlConnectionStringBuilder[^].
var conStringBuilder = new SqlConnectionStringBuilder
    {
        UserID = @"something",
        Password = @"passphrase",
        DataSource = @".\SQLExpress",
        InitialCatalog = @"MyDatabase"
    };
var connectionString = conStringBuilder.ConnectionString;


我知道我曾经使用过.Net 4.0语法,但是可以从.Net 2.0中获得此类.因此,它应该可以帮助您相应地更改用户名密码并生成所需的连接字符串.

希望这对您有所帮助


I know I''ve used .Net 4.0 syntax but this class is available from .Net 2.0. So it should help you to change the username password accordingly and generate the desired connection string.

Hope this helps, regards


想象一下您的MS Access连接字符串如下所示:

Imagine your connection string for MS Access would look like this:

Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\mydatabase.mdb;User Id=admin;Password=;"



现在,通过代码使密码可互换,您可以像这样重写它:



Now to make the password interchangeable by code you rewrite it like so:

Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};User Id=admin;Password={1};



然后,您可以在代码中执行以下操作:



You can then do something like this in your code:

String connectionStringPattern = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};User Id=admin;Password={1};";
foreach(currentFileName in listOfAccessFileNames)
{
    String connectionStringPatternWithFile = String.Format(connectionStringPattern, new String[] {currentFileName, "{0}");
    String passWord1 = "firstPassword";
    String passWord2 = "secondPassowrd";

    String connectionString1 = String.Format(connectionStringPatternWithFile, passWord1);
    String connectionString2 = String.Format(connectionStringPatternWithFile, passWord2);

    // Here place some code where you would try to open a connection to the current Access file 
    // using both variants of the password
}



希望你能明白!

—曼弗雷德(Manfred)



Hope you get the idea!

— Manfred


问题不明确.


这篇关于相同的连接字符串但密码不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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