Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can I use SQLConnection with .sdf files. I keep getting an error when I try to access data via a query (I can't connect to the database file)
Posted

1 solution

Don't use SQL server to connect to .SDF file - use an SqlCeConnection and SqlCeCommand instead:
C#
using (SqlCeConnection con = new SqlCeConnection(@"Data Source=C:\Users\griff\Documents\AA Backed Up\My Databases\StandardReplies.sdf"))
    {
    using (SqlCeCommand cmd = new SqlCeCommand("SELECT * FROM Replies", con))
        {
        using (SqlCeDataReader reader = cmd.ExecuteReader())
            {
            while (reader.Read())
                {
                ...
                }
            }
        }
    }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900