嗨我試圖連接一個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