嗨我试图连接一个SQL服务器压缩数据库到我的程序,我想要一个按钮,从数据库中删除所有条目,当我按下按钮时,程序抛出异常并给出以下错误消息“建立与SQL Server的连接时发生网络相关或实例特定的错误未找到服务器或无法访问服务器验证实例名称是否正确以及SQL Server是否配置为允许远程连接。(提供商:SQL网络接口,错误:26 - 错误定位服务器/实例指定)“将C#连接到SQL Server Compact数据库
帮助请吗? =]
对不起,代码如下=]
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中打开它吗? – Arran 2013-03-01 12:09:11
您是否传递正确的凭据,指向正确的SQL Server实例和数据库? – 2013-03-01 12:15:21
我指向本地存储的SQL服务器压缩数据库和目录名称正确 – 2013-03-01 12:17:54