Unable to load the native components of SQL Server Compact

Lakshman Balasubramanian 21 Reputation points
2024-04-22T19:03:42.12+00:00

Hello All,

I am trying to create a local database programmatically using C# with Sql server compact edition. I have Visual Studio 2019 and created a project with .NET framework of version 4.8. I have the following code which will create a database.

string connectionString = "DataSource=\"test.sdf\"; Password=\"mypassword\"";

SqlCeEngine en = new SqlCeEngine(connectionString);

en.CreateDatabase();

Unfortunately, when executed it throws the following error:

Unable to load the native components of SQL Server Compact corresponding to the ADO.NET provider of version 8876. Install the correct version of SQL Server Compact. Refer to KB article 974247 for more details.'

What is the reason of the error? Also, the error pointed to the second line of the above code where I have initiated SqlCeEngine.

It would helpful, if some one can suggest me which version is the correct version.
Thanks in Advance.

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,395 questions
Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,620 questions
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,755 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,274 questions
0 comments No comments
{count} votes

Accepted answer
  1. Castorix31 81,741 Reputation points
    2024-04-22T20:19:55.2833333+00:00

    You must have the SQLCE DLLs (for 4.0, sqlceme40.dll, etc...) in the path or in the exe directory

    (see for example https://www.codeproject.com/Questions/612858/Unable-to-load-the-native-components-of-SQL-Server)

    In my case, I have the 4.0 version with the DLLs in the path at

    C:\Program Files (x86)\Microsoft SQL Server Compact Edition\v4.0

    and if I rename sqlceme40.dll to do a test, I get the same error you posted.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 56,686 Reputation points
    2024-04-22T20:07:31.23+00:00

    you get this error when you try to run the 32 bit version of a 64 bit machine. did you install the 64 bit version as required?

    https://www.microsoft.com/en-us/download/details.aspx?id=30709

    note: SQL Server Compact support ended a couple years ago.

    0 comments No comments