從C#連接到SQL Server 2008 R2,我有一個嚴重的問題,因爲我已經改變了一些SQL Server設置。現在,我可以不通過下面的代碼連接到SQL Server:SQL插入不工作c#querybuilder
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
kamiDataSetTableAdapters.kami2TableAdapter kap = new WindowsFormsApplication1.kamiDataSetTableAdapters.kami2TableAdapter();
decimal a = Convert.ToDecimal("11.2");
int b = 11;
kap.Insert(Convert.ToDecimal("11.2"), b, Convert.ToDecimal("11.2"), Convert.ToDecimal("11.2"));
}
}
}
(表中有四個小數和一個INT列)
但是我可以連接並插入或QueryBuilder的選擇字段GUI。不幸的是,由於名譽低下,我無法上傳圖片。
和錯誤是
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. (provider: TCP Provider, error: 0 - No connection could be made because the target machine actively refused it.)
請你指導我,我的老闆很生氣!
預先感謝您。
連接字符串在哪裏?您確定SQL Server正在運行並配置爲接受遠程連接嗎?該錯誤消息似乎很清楚什麼是錯的... – 2012-08-11 15:58:59
聽起來像SQL Server實例不允許遠程連接,這將是我會檢查的第一件事。看看你是否可以Telnet到端口1433上的SQL Server實例。 – 2012-08-11 16:05:39
是啊sql正在運行,因爲我可以通過querybuilder連接並執行命令。 – 2012-08-11 20:18:39