Search code examples
delphidelphi-7ado

PromptDataSource in Delphi 7 is giving different results it did before


In my Delphi 7 application it is possible to build connections to sql server and store the connectionstrings in an config file.
This has always worked without any troubles for years now.

The code for building the connection string is this :

procedure TDataModuleMain.GetADOProviderString;
var
  ConnectionString : string;
begin
  ConnectionString := PromptDataSource(Application.MainForm.Handle, cdsConnectionsADOConnectionString.AsString);

  if ConnectionString <> cdsConnectionsADOConnectionString.AsString then
  begin
    if not (cdsConnectionsADO.State in [dsEdit, dsInsert]) then
      cdsConnectionsADO.Edit;
    cdsConnectionsADOConnectionString.AsString := ConnectionString;
  end;
end;

PromptDataSource is a function from the ADODB.pas and it brings up the Microsoft datalink property window and after configuring the connection the connectionstring is returned.

In the past I was able to uncheck Blank password and check Allow saving password and the password and security info=true was present in the returned connectionstring.
But this has changed some time ago, not sure when. The function now never returns the password and does not contains security info=true anymore. As a result these checkboxes always revert back and the password is always empty as in this screenshot : enter image description here

I suspect some windows update has done this to me, or could it be something else ?
I hope someone has encountered this and has a solution for it.

EDIT 1
It appears the problem only occurs when I choose SQL Server Native Client 11.0 as Provider. When I choose Microsoft OLE DB Provider for SQL Server there is no problem and everything works fine.
Is there a way to make the Native Client behave and also return the desired connectionstring ? The OS I am testing on is Windows 8.1

EDIT 2
I tried setting the property persistant security info=true as suggested in the comments, but again this gets reverted when using the native client but not when using the OLE DB client

EDIT 3
I tried it by making a text file with extension .udl and doubleclicking on it, as suggested in the comments. The result is the same, it works for OLE DB provider but not for the native client


Solution

  • The key is Persist Security Info=True (which is BTW not recommended for security reasons). The thing about Native Client 10/11 is that any change to the user name or password in the Data Link dialog will reset Persist Security Info to False.

    So you must enter the All tab after you change the username/password and change Persist Security Info to True. You might be presented with an information dialog stating that saving an unencrypted password is not recommended.

    enter image description here