C#链接SQL Server 2005的问题

plottowan_1977 plottowan_1977 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
Web server, SQL Server都在本机上。
连接语句如下:
SqlConnection conn;
conn= new SqlConnection("server=192.168.11.3;database=TestDb;uid=TestDb_Admin;pwd=123456789");
conn.Open();

奇怪的是,如果是一个C#, WinForm的程序,这个链接可以成功,并且已经可以INSERT数据到表里了。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
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)
{
SqlConnection conn;
conn= new SqlConnection("server=192.168.11.3;database=TestDb;uid=TestDb_Admin;pwd=123456789");
conn.Open();


但是,如果是在Web上面,同样的

SqlConnection conn;
conn= new SqlConnection("server=192.168.11.3;database=TestDb;uid=TestDb_Admin;pwd=123456789");
conn.Open();

报告错
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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
这是为什么?
...全文

相关推荐

评论 21
收藏 已收藏
分享
返回顶部
plottowan_1977
C# 111,129 成员 642,538 内容