SQLConnection与SQLServer compact 3.5(.sdf文件) [英] SQLConnection with SQLServer compact 3.5 (.sdf files)

查看:73
本文介绍了SQLConnection与SQLServer compact 3.5(.sdf文件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将SQLConnection与.sdf文件一起使用。当我尝试通过查询访问数据时,我一直收到错误(我无法连接到数据库文件)

解决方案

不要使用SQL服务器连接到.SDF文件 - 改为使用SqlCeConnection和SqlCeCommand:

 使用(SqlCeConnection con = < span class =code-keyword> new  SqlCeConnection( @  Data Source = C:\ Users \ griff \Documents; \\ AAA备份\我的数据库\StandardReplies.sdf))
{
使用(SqlCeCommand cmd = new SqlCeCommand( SELECT * FROM回复,con))
{
使用(SqlCeDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
...
}
}
}
}


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)

解决方案

Don''t use SQL server to connect to .SDF file - use an SqlCeConnection and SqlCeCommand instead:

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())
                {
                ...
                }
            }
        }
    }


这篇关于SQLConnection与SQLServer compact 3.5(.sdf文件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆