连接到SQL数据库 [英] Connecting to SQL database

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

问题描述

我想从C#应用程序连接到名为Northwind.sdf的示例数据库。我使用了以下连接字符串:

I want to get connected to sample database named Northwind.sdf from C# application. I used following connection string:

string source=@"Data source=C:\Northwind.sdf"





文件位于指定的位置,但每当我执行程序时,我都会收到以下错误: -



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





有谁能告诉我如何解决这个问题?



我是SQL新手。



提前谢谢。



The file was in the location specified but whenever I execute the program I get the following error:-

A network-related or instance-specific error occured 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 not configured to allow remote connections. (provider:SQL network Interfaces, error: 26 - Error locating Server/Instance Specified)


Can anyone tell me how to solve the problem?

I am new to SQL.

Thanks in advance.

推荐答案

SDF文件很可能(在这种情况下)是和SqlCE文件,而不是SQL文件。这是一个不使用SQL服务器的独立数据库。



相反,使用SqlCEConnection和SqlCECommand类,你应该没问题。您将需要引用System.Data.SqlServerCe程序集(在system.data.sqlserverce.dll中)。

请参阅MSDN [ ^ ]了解更多详情。



错别字 - OriginalGriff [/ edit]



非常感谢你的回答。它工作得很好。好的,你能告诉我吗我可以SqlCEConnection可以做SqlConnection可以做的所有事情吗? - Shah Rukh Qasim 6分钟前





它可以做很多事情(一个很好的描述是这里 [ ^ ])。主要区别在于它是单用户而不是多用户,适用于独立应用程序。

SQLServer可以读取这些内容(但根据我的经验,这可能会很麻烦)。这里有一个查询工具: SQL Server CE查询工具 [ ^ ]这有点不那么痛苦了。



它很方便,语法相同等等,只是你不需要安装SQL Server,因为.NET程序集在内部处理它。这可以使分发更容易,并且比有时使用XML数据文件更灵活!
An SDF file will most likely (in this case) be and SqlCE file, rather than an SQL file. This is a stand alone database that does not use SQL server.

Instead, use the SqlCEConnection and SqlCECommand Classes and you should be fine. You will need to reference the System.Data.SqlServerCe assembly (in system.data.sqlserverce.dll).
See MSDN[^] for more details.

[edit]Typos - OriginalGriff[/edit]

"Thanks a lot for your answer. It worked perfectly fine. OK can you please tell me that can the SqlCEConnection can do all things that SqlConnection can? - Shah Rukh Qasim 6 mins ago"


It can do pretty much everything (a good description is here[^]). The main difference is that it is single user rather than multiuser and intended for standalone applications.
SQLServer can read these (but it can be a pain to do sometimes in my experience). There is a query tool here: SQL Server CE Query Tool[^] which is a little less painful.

It''s handy to have, the syntax is the same etc., just you don''t need SQL Server installed because the .NET assembly handles it all internally. This can make distribution easier, and be a lot more flexible than using XML data files sometimes!


参见 this [ ^ ] -



重要如果您使用的是Windows Vista,如果Visual Studio在非管理员中运行,则无法连接到Northwind.sdf为了建立与Northwind.sdf的连接,数据库文件不应该在Windows目录,Program Files目录或系统驱动器中。它应该在用户目录或其他驱动器中。要连接到Northwind.sdf,请启动以管理员身份运行的Visual Studio。
See this[^] -

"Important If you are using Windows Vista, you cannot connect to the Northwind.sdf if Visual Studio is running in a non-administrator mode. To make a connection to Northwind.sdf, the database file should not be in Windows directory, Program Files directory, or system drive. It should be in a user directory or some other drive. To connect to the Northwind.sdf, start Visual Studio in the Run as administrator mode."


我看到你正在使用sdf文件编程。

你知道.sdf文件吗?它用于数据库。我打算做一个sdf查看器,但我不知道从哪里开始。你能帮助我吗?

我需要使用vb.net制作一个sdf查看器应用程序(基于窗口)
i see that you''re programming using sdf files.
do you know about .sdf files? its use for databases. i am going to make a sdf viewer but i dont know where to start. can you help me?
i need to make a sdf viewer application using vb.net (window-based)


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

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