SQL Server and thread

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
alemio
Posts: 12
Joined: Wed 20 May 2015 14:31

SQL Server and thread

Post by alemio » Wed 20 May 2015 14:40

Hi, I'm testing unidac with sql server to buy it.

I created a thread.

The Execute function is that:

void __fastcall UpdateThread::Execute()
{
SetName();
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);

_uniConnection = new TUniConnection(NULL);
_uniConnection->ProviderName = "SQL Server";
_uniConnection->Database = "RaceManagerDevelopment";
_uniConnection->SpecificOptions->Add("SQL Server.Authentication=auWindows");
_uniConnection->Pooling = true;
_uniConnection->Server = "NB-ALESSANDROM\SQLEXPRESS";
_uniConnection->LoginPrompt = false;
_uniConnection->Connected = true;
CoUninitialize();
}
//---------------------------------------------------------------------------

The thread freezes when execute Connected = true.

It happens also if I pass a working connection to the thread (anotherConnection comes form main thread and works fine)

_uniConnection = new TUniConnection(*anotherConnection);
_uniConnection->Connected = true;

Please let me know what is wrong

Regards

azyk
Devart Team
Posts: 1119
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: SQL Server and thread

Post by azyk » Fri 22 May 2015 13:11

To set the TUniConnection->Server property in your code to NB-ALESSANDROM\SQLEXPRESS , you should use a double-backslash, since a single backslash in a string value will be interpreted by C++Builder as escape sequence. For this, replace the following line in your code:

Code: Select all

_uniConnection->Server = "NB-ALESSANDROM\SQLEXPRESS";
with this one:

Code: Select all

_uniConnection->Server = "NB-ALESSANDROM\\SQLEXPRESS";

Post Reply