Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TAdoConnection password goes AWOL

Tags:

delphi

Using a TAdoConnection in D5 to connect to a local Sql Server on a Windows 7 64-bit machine using a passworded sa account, I get the error "login failed for user sa", despite the fact that I've built the TAdoConnection ConnectionString to include the password. By the time the BeforeConnect event triggers, the ConnectionString no longer contains the password. I can set the password in the WillConnect event and the connection then works fine.

My question is, what's removing the password from the ConnectionString? Is it maybe some security feature added in W7 - I don't recall getting this problem on XP.

Btw: This problem still happens even if I set Persist Security Info to true in the ConnectionString - the password doesn't even get stored in the DFM.

like image 667
MartynA Avatar asked Aug 08 '13 11:08

MartynA


1 Answers

Your ConnectionString needs to include "Persist Security Info=True" see this prior topic. I use two const, one for SQL Authentication and the other for Active Directory Authentication and just fill in the blanks.

const
  csCONNECTION   = 'Provider=%s;Password=%s;Persist Security Info=True;User ID=%s;Initial Catalog=%s;Data Source=%s';
  csADCONNECTION = 'Provider=%s;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=%s;Data Source=%s';
like image 66
TDC Avatar answered Nov 16 '22 18:11

TDC