VB脚本中Oracle OLE DB如何实现无密码连接?Oracle Wallet集成咨询
Hey there! Let's walk through how to integrate Oracle Wallet with your VB Script for password-less database access, plus a couple other solid options since OS authentication isn't on the table.
Using Oracle Wallet with OraOLEDB.Oracle
Since your server already has Oracle Wallet deployed, the main steps are configuring your client (the machine running the VB Script) and updating your connection string:
Client-side configuration
First, ensure your Oracle Client (or Instant Client) is set up to use the wallet:- Locate your
sqlnet.orafile (typically inORACLE_HOME/network/adminor%APPDATA%\Oracle\network\adminfor Windows) and add these lines:SQLNET.WALLET_OVERRIDE = TRUE WALLET_LOCATION = (SOURCE = (METHOD = FILE) (METHOD_DATA = (DIRECTORY = C:\path\to\your\wallet))) - Keep your existing
tnsnames.oraentry forMyOracleDB—it should still point to your database as before. - Double-check that the wallet contains the correct credentials for
MyOracleDB. If not, use themkstorecommand to add them:mkstore -wrl C:\path\to\wallet -createCredential MyOracleDB myUsername myPassword
- Locate your
Update your VB Script connection string
Remove theUser IdandPasswordparameters entirely. Your script will now look like this:Dim conn Set conn = CreateObject("ADODB.Connection") ' No username/password needed—wallet handles authentication conn.ConnectionString = "Provider=OraOLEDB.Oracle;Data Source=MyOracleDB;" conn.OpenThe OraOLEDB provider will automatically pull credentials from the wallet for the specified data source. You can test this first with
sqlplus /@MyOracleDBto confirm the wallet works without a password.
Alternative Password-Less Options
If you need backup solutions beyond the wallet, here are two viable approaches:
1. External Authentication (DBA-configured)
If your Oracle database is set up to support external authentication (like SSL certificates or third-party identity providers), you can use this with OraOLEDB. Adjust your connection string to enable external auth:
Dim conn Set conn = CreateObject("ADODB.Connection") conn.ConnectionString = "Provider=OraOLEDB.Oracle;Data Source=MyOracleDB;External Authentication=True;" conn.Open
Note: This requires your DBA to configure the database to accept external authentication for your user account—reach out to them to set this up first.
2. Encrypted Local Credential Storage
Store your encrypted password in a secure local file, then decrypt it at runtime in your script. Use Windows' built-in crypto APIs to avoid rolling your own encryption (which is risky). Here's a simplified example:
' Decrypts a stored password using Windows CAPICOM Function DecryptPassword(encryptedData) Dim objCrypt Set objCrypt = CreateObject("CAPICOM.EncryptedData") objCrypt.Decode(encryptedData) DecryptPassword = objCrypt.Content End Function ' Read encrypted password from a restricted file Dim fso, file, encryptedPass Set fso = CreateObject("Scripting.FileSystemObject") ' Ensure this file has strict permissions (only your script user can read it!) Set file = fso.OpenTextFile("C:\secure\encrypted_cred.txt", 1) encryptedPass = file.ReadAll file.Close ' Build connection string with decrypted password Dim conn Set conn = CreateObject("ADODB.Connection") conn.ConnectionString = "Provider=OraOLEDB.Oracle;Data Source=MyOracleDB;User Id=myUsername;Password=" & DecryptPassword(encryptedPass) & ";" conn.Open
Critical: Lock down the encrypted file with NTFS permissions so only the user running the script can access it—this prevents unauthorized users from reading the encrypted data.
Quick Checks Before Deploying
- For the wallet approach, confirm the client machine can access the wallet directory (no permission issues).
- If using Instant Client, make sure the wallet files are placed in the correct location (usually the same folder as the Instant Client binaries, or reference it in
sqlnet.ora).
内容的提问来源于stack exchange,提问作者Alexis

