从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