CoInitialize Error with SQLServerUniProvider?
Posted: Wed 02 Oct 2013 17:53
I'm getting a strange error when attempting to use UNIDAC components in a service on Windows 7. I am using Delphi XE. Other services I have converted to UNIDAC work just fine, but this one in particular is giving me odd errors.
When I do not include SQLServerUniProvider in my uses, I am given an error stating that "You should add the SQLServerUniProvider unit to the uses clause of any unit..."
When I add SQLServerUniProvider in my uses, my service attempts to start, then immediately errors out and says "OLE DB Error occured. Code 800401F0h. CoInitialize has not been called." This error is triggered when I try to set Connected := True during a database connection attempt. This is my example, in which I see the log message "I made it this far!" only to have it error out on the next line.
Isn't CoInitialize handled in the background? What is going on here? If I manually add CoInitialize to my code, the service runs successfully, but I am blocked from starting my main application...
When I do not include SQLServerUniProvider in my uses, I am given an error stating that "You should add the SQLServerUniProvider unit to the uses clause of any unit..."
When I add SQLServerUniProvider in my uses, my service attempts to start, then immediately errors out and says "OLE DB Error occured. Code 800401F0h. CoInitialize has not been called." This error is triggered when I try to set Connected := True during a database connection attempt. This is my example, in which I see the log message "I made it this far!" only to have it error out on the next line.
Code: Select all
Connected := False;
Server := dbConfig.Server;
Database := dbConfig.Database;
Username := dbConfig.UserID;
Password := dbConfig.Password;
ProviderName := 'SQL Server';
logger.Log('I made it this far!');
Connected := True;
logger.Log('I did not make it this far!');