如何连接到sql compact或sdf数据库? [英] how to connect to sql compact or sdf database?

查看:142
本文介绍了如何连接到sql compact或sdf数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用此连接连接到我的.sdf数据库:

数据源= c:\\Database1.sdf



但是当我想通过 connection.open 打开连接时,会抛出此异常:



建立与SQL Server的连接时发生与网络相关或特定于实例的错误。未找到服务器或无法访问服务器。验证实例名称是否为正确并且SQL Server配置为允许远程连接。(提供程序:SQL网络接口,错误:26 - 找到指定的服务器/实例时出错)。



然后我无法连接到数据库。



如何修复此异常问题?

解决方案

Don尝试通过SQL服务器访问它 - 改为使用SqlCE连接。



这意味着替换:

SqlConnection与SqlCeConnection

SqlCommand with SqlCeCommand

等等。



您还需要提供对System.Data.SqlServerCe的引用(在system.data.sqlserverce.dll中) )

I use this connection to connect to my .sdf database:
"Data Source = c:\\Database1.sdf"

but when i want to open the connection by "connection.open", it throws this exception:

"A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)".

then I can't connect to the database.

how can I fix this exception problem?

解决方案

Don't try to access it via SQL server - use the SqlCE connections instead.

This means replacing:
SqlConnection with SqlCeConnection
SqlCommand with SqlCeCommand
and so forth.

You will also need to provide a reference to System.Data.SqlServerCe (in system.data.sqlserverce.dll)


这篇关于如何连接到sql compact或sdf数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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