[英]Local SQL Database not connecting
我正在嘗試連接到我正在從事的(初學者)項目的本地SQL數據庫。 我不知道如何連接到本地SQL數據庫。 我將數據庫添加到項目中,並且在測試連接時沒有任何錯誤。 每當我運行代碼(按button2)時,都會在con.Open()旁邊收到如下錯誤:
“建立與SQL Server的連接時發生了與網絡相關或特定於實例的錯誤。找不到服務器或無法訪問該服務器。請驗證實例名稱正確並且已將SQL Server配置為允許遠程連接。(提供者: SQL網絡接口,錯誤:26-錯誤定位服務器/實例指定)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net.Sockets;
using System.IO;
using System.Data.SqlClient;
using System.Data.SqlServerCe;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button5_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void button3_Click(object sender, EventArgs e)
{
// ofd wordt gedeclareerd voor de "Open file dialog"
OpenFileDialog ofd = new OpenFileDialog();
SqlConnection cn = new SqlConnection(Properties.Settings.Default.ImageDemoConnectionString);
但我指出我的設置中的數據庫正確。 我也嘗試過
Data Source = "Path\DB.sdf"
但這給了我同樣的錯誤。
如果有人可以給我提示嗎? 不勝感激!
您使用的連接類型錯誤。 SDF文件是SQL Compact Edition數據庫,需要與SqlCeConnection類連接。 另請參閱使用SQL Server Compact(Visual Studio)和SQL Server Compact的連接字符串 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.