do we need to call coInitialize() per instance or per database connection while connecting sql server?

parvathy priya 1 Reputation point

I am testing with MSSQL server 2008. I have configured multiple database in my application. When I try to connect the second database it throws HR error "0x800401f0" which says CO_E_NOTINITIALIZED and it was thrown when trying to create co-create instance for the second database connection. But already we have coInitialized when we connect default/first database. So do we need to Coinitialize per database connection or per instance?

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,692 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Michael Taylor 47,966 Reputation points

    CoInitialize sets up the COM infrastructure on a thread. Therefore you call it per-thread, not per database or instance. Ideally though call CoInitializeEx instead.

    Note that if you call it again it will return a successful failure (S_FALSE).

    2 people found this answer helpful.
    0 comments No comments

  2. Cris Zhan-MSFT 6,601 Reputation points

    Hi @parvathy priya ,

    This is more a programming problem than a SQL Server database connection problem, and perhaps more effective help can be obtained in the appropriate forum.
    Check the Remarks of the document: CoInitialize function

    And please check the following posts if help: