I have a Perl application on Windows which uses threads which run in parallel. Each thread accesses an MSSQL database.
I understand that I can't use Win32::OLE
because it is not thread safe.
Could you suggest me some another suitable solution for doing this?
Create a Windows service, which will access the database as a single thread and Perl will use this service?
Create another Perl app "server", which will access to DB as single thread app, and the Perl threads will use this service?
Use Win32::OLE
(DBI) library only in child threads or by some safe way?
I don't know what the right way is, and what the ways to solve it might be.
DBI
isn't dependent on anything other than the usual build and test modules that are used during installation
There is no DBD
driver for SQL Server (I'm not clear why. Perhaps someone would enlighten me?) so you will need to use an ODBC connection using the DBD::ODBC
driver
I'm unsure how DBI
behaves under threads, and I suggest you use fork
instead which is emulated on Windows versions of Perl. You will need to set $dbh->{AutoInactiveDestroy} = 1
to prevent processes from auto-destroying database and statement handles when they shouldn't