【发布时间】:2013-03-01 12:06:20
【问题描述】:
您好,我正在尝试将 SQL Server 紧凑型数据库连接到我的程序,我想要一个从数据库中删除所有条目的按钮,当我按下所述按钮时,程序抛出异常并给出以下错误消息“A network - 建立与 SQL Server 的连接时发生相关或特定于实例的错误。找不到服务器或无法访问该服务器。验证实例名称是否正确以及 SQL Server 是否配置为允许远程连接。(提供者:SQL Network Interfaces ,错误:26 - 定位服务器/指定实例时出错)”
请帮忙? =]
对不起,代码在下面 =]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data.SqlServerCe;
namespace Booking_system_Final
{
public partial class PendingJobs : Form
{
SqlConnection sc = new SqlConnection("Data Source=C:\\Users\\Administrator\\My Documents\\BMS_Data.sdf");
public PendingJobs()
{
InitializeComponent();
}
private void PendingJobs_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'bMSDataSet.Bookings' table. You can move, or remove it, as needed.
this.bookingsTableAdapter.Fill(this.bMSDataSet.Bookings);
// TODO: This line of code loads data into the 'bMS_DataDataSet1.Bookings' table. You can move, or remove it, as needed.
}
private void button1_Click(object sender, EventArgs e)
{
sc.Open();
SqlCommand cmd = new SqlCommand("DELETE FROM Bookings");
cmd.Connection = sc;
cmd.ExecuteNonQuery();
sc.Close();
MessageBox.Show("Database Cleared");
}
}
}
【问题讨论】:
-
那么让我们看看一些代码。另外,你能在 SQL Server Management Studio 中打开它吗?
-
您是否传递了正确的凭据,指向正确的 SQL Server 实例和数据库?
-
我指向的是本地存储的 SQL server Compact 数据库,目录名是正确的
-
这通常是因为 sdf 文件不存在。是吗?
-
是的,我在 Windows 资源管理器中检查了目录,并且 SDF 文件在那里,连接字符串直接指向该文件,我看不出我在哪里出错了
标签: c# sql sql-server-ce