Building a ConnectionString with a User-Supplied Password
Building a connection string with a user-supplied password is a very simple alternative to protect your data. For example, before rendering a report (or when the control reports a "failed to connect" error), you can prompt the user for a password and plug that into the connection string:
' build connection string with placeholder for password
Dim strConn
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\SecureData\People.mdb;" & _
"Password={{THEPASSWORD}};"
' get password from the user
Dim strPwd$
strPwd = InputBox("Please enter your password:")
If Len(strPwd) = 0 Then Exit Sub
' build new connection string and assign it to the control
strConn = Replace(strConn, "{{THEPASSWORD}}", strPwd)
vsr.DataSource.ConnectionString = strConn
• C#
// build connection string with placeholder for password
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=C:\SecureData\People.mdb;" +
"Password={{THEPASSWORD}};";
// get password from the user
string strPwd = InputBox("Please enter your password:");
if (strPwd.Length == 0) return;
// build new connection string and assign it to the control
strConn = Replace(strConn, "{{THEPASSWORD}}", strPwd);
c1r.DataSource.ConnectionString = strConn;
|