如何在ASP.NET连接到SQL Server Compact 4.0吗? [英] How connect to SQL Server Compact 4.0 in ASP.NET?

查看:209
本文介绍了如何在ASP.NET连接到SQL Server Compact 4.0吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想连接到SQL Server Compact 4.0在我的ASP.NET应用程序。

I want connect to SQL Server Compact 4.0 in my ASP.NET application.

下面是例子code的:

Here is example of code:

protected void Page_Load(object sender, EventArgs e)
{
    string connStr = "Data Source=D:\\MyDB.sdf;";
    string sqlStr = "select * from tblMyTable";

    var sqlDataSrc = new SqlDataSource(connStr, sqlStr);

    GridWithUrls.DataSource = sqlDataSrc;
    GridWithUrls.DataBind();
}

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

But I have the next error: "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)"

SqlDataSource控件有三个参数,其中之一就是'的providerName,所以,如何确定,我想肯定使用SQL Server精简供应商的构造?
我也有添加System.Data.SqlServerCe参考。

The SqlDataSource has constructor with three parameters, one of them is 'providerName' so, how to specify that I want definitely use Sql Server Compact provider ? Also I have added System.Data.SqlServerCe reference..

推荐答案

尝试:

providerName = "System.Data.SqlServerCe.4.0"

这篇关于如何在ASP.NET连接到SQL Server Compact 4.0吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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