Answer the question
In order to leave comments, you need to log in
How to enter password to MS Access database from non-printable characters from C# code?
Good day, dear colleagues!
Help me please. I ran into a problem I didn't know before.
There is quite a working MS Access database , *.mdb format , working with a desktop client. The password for access to the database is set with non-printable characters like \u0127 \u0027 \u0087 , and the like. Accordingly, it is impossible to enter them from the keyboard - but you can only get access programmatically by setting the appropriate password in the connection parameters. Yes, and in any case, the password cannot be changed.
The old client was written in Delphi , written a long time ago, but I know of a working function that collects a password to connect to the database:
//получение пароля
function TDBAccess.GetDBPass: string;
begin
Result := Chr(27) + Chr(8) + Chr(30) + Chr(23) +
Chr(31) + Chr(22) + Chr(2) + Chr(24) + Chr(127);
end;
// строка подключения
DBConnection = new OleDbConnection();
DBConnection.ConnectionString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Jet OLEDB:Database Password={1};", _path, _pass);
string _pass = @"\u0027\u0008\u0030\u0023\u0031\u0022\u0002\u0024\u0127";
var _pass_char = Convert.ToChar(27) + Convert.ToChar(8) + Convert.ToChar(30) + Convert.ToChar(23) + Convert.ToChar(31) + Convert.ToChar(22) + Convert.ToChar(2) + Convert.ToChar(24) + Convert.ToChar(127);
String _pass= Encoding.Default.GetString(_pass_char);
var _pass_char =(char)27 + (char)8 + (char)30 + (char)23 + (char)31 + (char)22 + (char)2 + (char)24 + (char)127
String _pass= Encoding.Default.GetString(_pass_char);
byte[] _hex_code = new Byte[] { 0x1B, 0x08, 0x1E, 0x17, 0x1F, 0x16, 0x02, 0x18, 0x7F };
String _pass= Encoding.Unicode.GetString(_hex_code);
var encoding = Encoding.GetEncoding(...)...
Answer the question
In order to leave comments, you need to log in
I asked the question myself - I answer it myself :)
You need it like this:
Everything, as always, is in the details...
Moreover, I thought about this method, but rejected it as too simple and obvious :) It turns out that it is also suitable for non-printable characters.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question