Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I am getting error when I am trying to open connection. My DB.sdf file is in my application folder

here i stored db.sdf

string ConnectionString= new System.IO.FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).DirectoryName + @"\APP_DATA\DB.sdf"; public int ExecuteNonQuery(string query){ int res = -1; using (SqlCeConnection conn = new SqlCeConnection(ConnectionString)) SqlCeCommand command = new SqlCeCommand(query, conn); command.CommandType = CommandType.Text; conn.Open(); res = command.ExecuteNonQuery(); catch (Exception e) new Logs().TraceProcessError(e.Message); return res;

Error:

You are trying to access an older version of a SQL Server Compact Edition database. If this is a SQL Server CE 1.0 or 2.0 database, run upgrade.exe. If this is a SQL Server Compact Edition 3.0 or later database, run Compact / Repair. [ Db version = 3505053,Requested version = 3004180,File name = D:\DB.sdf ]"

and I am using SQL Server Compact 3.5., VS2010, SQLServer 2008R2.

please help. thanks.

Copy the database file to your dekstop, and use my standalone SQL Server Compact Toolbxo to detect the file version, I imagine it is 2.0, and you need to upgrade or start anew (upgrade is very complicated, and must happen on device) ErikEJ Dec 6, 2013 at 9:42 I'm having the same problem. I ran SQL Server Compact Toolbox (very helpfull) and detected the database to be 3.5. It the toolbox and MS SQL Studio can read and interact with the database ok. The version numbers in the error are exactly the same as above. Keith Loughnane May 1, 2014 at 13:32 I found that I was using a 3.5 SQL compact file and a 3.0 SQL compact library. What was throwing me was for some reason I would delete the reference to the 3.0 library and replace it with the 3.5 one. But it went back somehow. Keith Loughnane May 7, 2014 at 10:07

Can you please refer to the link below:

http://social.msdn.microsoft.com/Forums/sqlserver/en-US/058357a2-e8a2-447e-82dc-df4466542855/trying-to-open-a-sql-compact-db-in-vb2005-created-it-in-vb2008?forum=sqlce

Hope it helps..!!

thanks @Daan ** My SQL Server CE database version and System.Data.SqlServerCe.DLL version, both are same i.e 3.5.5692.0 but steel its showing same error. I am using *vs2010 and 64 bit OS , I Installed and tried with System.Data.SqlServerCe.DLL, for both 32bit and 64bit system. Actually my requirement is , I have to prepare ** SQL Server CE database with data* using WPF/windows application and dump it to windows device. but I am unable to open database connection in Application. Raam Dec 6, 2013 at 9:39

https://sqlcetoolbox.codeplex.com/

Run it against your data base file and note down the version number (eg. 3.5)

Go into visual studio click on System.Data.SqlServerCe under resources and then click under the properties. In properties note down the version number (eg. 3.0)

If the the library version number is older. Download the SQL Server Compact installer and run. http://www.microsoft.com/en-IE/download/details.aspx?id=12264

Once installed. Delete the references to System.Data.SqlServerCe and System.Data.SqlClient from your project and add their equivalent 3.5 versions. Found on my system at.

C:\Program Files (x86)\Microsoft SQL Server Compact Edition\v3.5\Devices\System.Data.SqlServerCe.dll

C:\Program Files (x86)\Microsoft SQL Server Compact Edition\v3.5\Devices\Client\System.Data.SqlClient.dll

Clean and then rebuild. Like I mentioned in the comment, this undid itself at some point on VS 2008 so if you get the error again double check the path is going to the above.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question . Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers .