c#项目中的sql server compact sdf文件 - SQLException的问题 [英] sql server compact sdf file within c# project - problems with SQLException

查看:128
本文介绍了c#项目中的sql server compact sdf文件 - SQLException的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题与以前的 SO问题

我已经修复了程序中使用的字符串,因此现在运行该代码行。

I have fixed the string used in the program so it now runs that line of code.

为什么以下错误在 myAdapt.Fill(mySet,AvailableValues); 错误 SQLException未被处理;建立与SQL Server的连接时发生网络相关或实例特定的错误。服务器未找到或无法访问。验证实例名称是否正确,并将SQL Server配置为允许远程连接

Why does the following fail on the line myAdapt.Fill(mySet, "AvailableValues"); with a error SQLException was Unhandled; 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

数据库是项目的一部分,为什么要这样连接困难

The database is part of the project so why should there be difficulties connecting?


  • 我尝试在sql文件中运行sql字符串,运行正常。

  • 我尝试删除DGV中的所有列。

  • I've tried running the sql string in a sql file and it runs ok.
  • I've tried deleting all columns from the DGV.

void PopulateGridView()
{
    SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DatabaseDGVexperiments.Properties.Settings.DatabaseDGVexperimentsConnStg"].ConnectionString);
    SqlDataAdapter myAdapt = new SqlDataAdapter("SELECT refText FROM helloworld", conn);
    DataSet mySet = new DataSet();
    myAdapt.Fill(mySet, "AvailableValues");
    DataTable myTable = mySet.Tables["AvailableValues"];
    this.uxExperimentDGV.DataSource = myTable;
}


推荐答案

您是否尝试使用SqlConnection打开一个SqlCE文件(SDF)?

我认为您应该使用SqlCeConnection和特定于Sql Compact的ADO.NET类

Are you trying to open a SqlCE file (SDF) with SqlConnection?
I think you should a use SqlCeConnection and the ADO.NET classes specific for Sql Compact

using System.Data.SqlServerCe;
.....

void PopulateGridView() 
{ 
    SqlCeConnection conn = new SqlCeConnection(ConfigurationManager.ConnectionStrings["DatabaseDGVexperiments.Properties.Settings.DatabaseDGVexperimentsConnStg"].ConnectionString); 
    SqlCeDataAdapter myAdapt = new SqlCeDataAdapter("SELECT refText FROM helloworld", conn); 
    DataSet mySet = new DataSet(); 
    myAdapt.Fill(mySet, "AvailableValues"); 
    DataTable myTable = mySet.Tables["AvailableValues"]; 
    this.uxExperimentDGV.DataSource = myTable; 
} 

这篇关于c#项目中的sql server compact sdf文件 - SQLException的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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