SQL数据库连接 [英] SQL Database Connecting

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

问题描述

我是SQL新手.有经验的人想协助吗?

我想从C#应用程序连接到名为codeproject.sdf的示例数据库.

我使用了以下连接字符串:
字符串源= @数据源= C:\ codeproject.sdf"

该文件位于指定的位置,但是每当我执行程序时,都会出现以下错误:

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

I am new to SQL. Any veterans want to assist?

I want to get connected to sample database named codeproject.sdf from C# application.

I used following connection string:
string source=@"Data source=C:\codeproject.sdf"

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)

Thanks!

推荐答案

您可能需要运行Windows CE和SQL Server Mobile Edition的SQL Server才能访问此文件.
You probably need to be running SQL Server for Windows CE and SQL Server Mobile Edition to access this file.


您需要使用正确的连接字符串.

参见 http://www.connectionstrings.com/sql-server-2008 [ http://www.connectionstrings.com/sql-server-2005-ce [ ^ ]
You need to use a proper connection string.

See http://www.connectionstrings.com/sql-server-2008[^]

That link''s for SQL Server 2008 but you should be able to find one that matches your version.

After seeing Abhinav''s response, here''s a page that lists suitable connection strings for SQL Srver CE:

http://www.connectionstrings.com/sql-server-2005-ce[^]


访问.SDF文件,您根本不需要使用SQL Server,.NET中内置了SqlCE支持.
只需添加对System.Data.SqlServerCe命名空间的引用,并为您的代码添加using System.Data.SqlServerCe;.
然后,您可以通过SqlCeConnection和SqlCeCommand类访问数据库.在此处有一个演练:MSDN [
To access a .SDF file you do not need to use SQL server at all, SqlCE support is built into .NET
Just add a reference to the System.Data.SqlServerCe namespace and a using System.Data.SqlServerCe; to your code.
You then access the database via the SqlCeConnection and SqlCeCommand classes. There is a walkthrough here: MSDN[^]


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

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