Page 1 of 1

Threading issues..

Posted: Thu 28 Jan 2016 17:32
by FredS
Just a heads-up.

Using a DataModule within a thread I got "Windows logins are not supported in this version of SQL Server"
from an Azure db.
Now I know it works because I have used threads before via:

Code: Select all

 TUniConnection.Create(nil, ConnectString).
After some monkeying around I could get the DataModule thread to work "consistently"only after removing all SpecificOptions, ProviderName, Database and Macros and using:

Code: Select all

 UniConnection.connect(ConnectString)

Re: Threading issues..

Posted: Tue 02 Feb 2016 09:00
by azyk
We can't reproduce the reported error according to your recommendations. Let us know the value the ConnectString you are using for connection to Azure SQL Database.

Re: Threading issues..

Posted: Tue 02 Feb 2016 17:34
by FredS
azyk wrote:We can't reproduce the reported error according to your recommendations. Let us know the value the ConnectString you are using for connection to Azure SQL Database.
I should add the test was from my local machine to an Azure db.

Code: Select all

'Provider Name=SQL Server;Provider=SQLOLEDB.1;Data Source=<ServerName>.DATABASE.WINDOWS.NET;Initial Catalog=PA;Force Create Database=False;User ID=fred;Password=<Pwd>;Login Prompt=False'
Maybe I should add what I had that caused the issue:

Code: Select all

object UniConnection: TUniConnection
  ProviderName = 'InterBase'
  Database = 'D:\My Projects\db\PA.FDB'
  SpecificOptions.Strings = (
    
      'InterBase.ClientLibrary=C:\ProgramData\Firebird\fb3\fbclien' +
      't.dll'
    'InterBase.Charset=UTF8'
    'InterBase.UseUnicode=True'
    'SQL Server.Authentication=auWindows'
    'InterBase.Role=RDB$ADMIN'
    'SQL Server.ForceCreateDatabase=False'
    'InterBase.ForceUnloadClientLibrary=True'
    'SQL Server.Provider=prSQL')
  Options.AllowImplicitConnect = False
  Options.KeepDesignConnected = False
  Options.DefaultSortType = stCaseInsensitive
  Macros = <
    item
      Name = 'True'
      Value = 'TRUE'
      Condition = 'InterBase'
    end
    item
      Name = 'True'
      Value = '1'
      Condition = 'SQLServer'
    end
    item
      Name = 'False'
      Value = 'FALSE'
      Condition = 'InterBase'
    end
    item
      Name = 'False'
      Value = '0'
      Condition = 'SQLServer'
    end
    item
      Name = 'FROMRDBDatabase'
      Condition = 'SQLServer'
    end
    item
      Name = 'FROMRDBDatabase'
      Value = 'FROM RDB$Database'
      Condition = 'InterBase'
    end
    item
      Name = 'concat'
      Value = '||'
      Condition = 'InterBase'
    end
    item
      Name = 'concat'
      Value = '+'
      Condition = 'SQLServer'
    end
    item
      Name = 'First'
      Value = 'First'
      Condition = 'InterBase'
    end
    item
      Name = 'First'
      Value = 'Top'
      Condition = 'sQLServer'
    end>
  Username = 'SYSDBA'
  LoginPrompt = False
end

Re: Threading issues..

Posted: Wed 03 Feb 2016 08:52
by azyk
The provided dfm code for UniConnection contains a line that sets Windows Authentication for the SQL Server provider:

Code: Select all

    'SQL Server.Authentication=auWindows'
Since the Authentication parameter is not specified in the used connection string, then on connection this UniConnection will use Windows Authentication. To use SQL Server Authentication, set the Authentication connection string parameter to 'Server'. For example:

Code: Select all

'Provider Name=SQL Server;Provider=SQLOLEDB.1;Data Source=<ServerName>.DATABASE.WINDOWS.NET;Initial Catalog=PA;Force Create Database=False;User ID=fred;Password=<Pwd>;Login Prompt=False;Authentication=Server'

Re: Threading issues..

Posted: Wed 03 Feb 2016 16:41
by FredS
azyk wrote:The provided dfm code for UniConnection contains a line that sets Windows Authentication for the SQL Server provider
The connectionstring comes from the main connection and there I have this code:

Code: Select all

          if UserPrefs.ReadBool('Database', 'UseWindowsAuth', True) then begin
            SpecificOptions.Values['SQL Server.Authentication'] := 'auWindows';
            Username := EmptyStr;
            Password := EmptyStr;
          end else begin
            SpecificOptions.Values['SQL Server.Authentication'] := 'auServer';
            Username := UserPrefs.ReadString('Database', 'Login', EmptyStr);
            Password := EnCrypt(<pwd>, ecUnlock);
          end;
Shouldn't the Connectionstring which we pass on to threaded connections override any dfm entries?

Re: Threading issues..

Posted: Fri 05 Feb 2016 13:00
by azyk
When you set a value for TUniconnection.ConnectString, it will override only mentioned connection string parameters of this connection instance.

Re: Threading issues..

Posted: Fri 05 Feb 2016 16:53
by FredS
azyk wrote:When you set a value for TUniconnection.ConnectString, it will override only mentioned connection string parameters of this connection instance.
OK, so for threading we pass the main connection string to any threads, but if design time parameters are set which are NOT explicitly set in the connection string we need to clear them.