使用 C1Report 控件 > 高级功能 > 数据安全性 > 使用用户提供的密码创建连接字符串(ConnectionString) |
使用用户提供的密码创建连接字符串是一种非常简单的保护数据的方法。 例如在渲染报表之前(或当控件提示“无法连接”的错误时),可以提示用户输入密码,并把该密码插入到连接字符串:
Visual Basic
Visual Basic |
拷贝代码
|
---|---|
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#
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; |