Page 1 of 1

SQL Server and thread

Posted: Wed 20 May 2015 14:40
by alemio
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

Re: SQL Server and thread

Posted: Fri 22 May 2015 13:11
by azyk
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";