如何在桌面应用程序中连接.sdf文件 [英] How to connect to .sdf file in a desktop application

查看:93
本文介绍了如何在桌面应用程序中连接.sdf文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我开发了一个桌面应用程序,但是Local Based Server意味着.sdf文件作为数据库。当我想连接时:



我在APP.config文件中有连接和



Hi,
I have developed a desktop application but there is Local Based Server means .sdf file as a database. When I want to connect through:

I have connection in APP.config file and

SqlConnectionstring con=new sqlConnection()
con.Open()



这是一个与网络相关的错误信息:



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



如何连接到基于本地的服务器?如何解决这个问题?


This got an network related error message:

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)".

How to connect to Local based server? How to Solve this Problem?

推荐答案

你必须将 ConnectionString 放入 SQLCEConnection 对象之前打开连接。





请参阅

SQLCEConnection构造函数
[ ^ ]例如。



如何按名称检索ConnectionString的示例

示例:按名称检索连接字符串 [ ^ ]



有关从配置文件获取ConnectionString的其他文档

Configuration.ConnectionStrings属性 [ ^ ]

Configuration.AppSettings Property [ ^ ](已废弃)
You must put the ConnectionString into the SQLCEConnection object before you Open the connection.


See
SQLCEConnection Constructor
[^] for an example.

Example of how to retrieve ConnectionString by Name
Example: Retrieving a Connection String by Name[^]

Other documentation about getting ConnectionString from config file
Configuration.ConnectionStrings Property [^]
Configuration.AppSettings Property[^](Obsolete)


上面的代码甚至不会编译(你的类类型错​​误),而你缺少实际的连接字符串;你的代码应该是这样的:

The above code would not even compile (your class types are wrong), and you are missing the actual connection string; your code should be something like:
SqlCeConnection con = new SqlCeConnection(Properties.Settings.Default.DBConnection);
con.Open();


这篇关于如何在桌面应用程序中连接.sdf文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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