sql与asp.net的连接问题

标签 sql visual-studio

我正在使用 vs2010,我已经尝试了所有可能的方法来连接来自 Visualstudio 的数据库,请帮助我这里是代码

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;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            SqlConnection cs = new SqlConnection("Data Source=Sql Server(SQLEXPRESS); Initial Catalog=school");
            cs.Open();
                MessageBox.Show(cs.State.ToString());
                cs.Close();
        }
    }
}

它无法连接并给出错误: 建立与 SQL Server 的连接时发生与网络相关或特定于实例的错误。服务器未找到或无法访问。验证实例名称是否正确以及 SQL Server 是否配置为允许远程连接。 (提供程序:命名管道提供程序,错误:40 - 无法打开与 SQL Server 的连接)

帮助

最佳答案

嘿,我已经做到了,它非常简单,我研究了转义序列,解决方案是我们应该放置 2 个反斜杠,而不是一个反斜杠,哈哈,也许这也会帮助其他人,如果你运行 Express,这是必要的

SqlConnection cs = new SqlConnection("数据源=您的电脑名称\\SQLEXPRESS;初始目录=学校;集成安全性=true")

记住在你的电脑名称后面加上 2 个反斜杠:) :)

感谢各位 friend 的解答

关于sql与asp.net的连接问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4338219/

相关文章:

c++ - 如何使应用程序具有大地址感知能力?

java - 我尝试更新我的jdk但没有修复它(Visual studio代码)1.38版本

sql - 为什么 ActiveRecord 会为大多数操作生成参数化查询,但不会为 find_by 生成参数化查询?

java - SQL异常 : ORA-01008: not all variables bound -- SQL error using java to query database JDBC

sql - 如何解决单行子查询返回多行的问题

c# - 负载测试 Visual Studio,启动脚本/设置

sql - 数据库恢复 - 用于列出安全对象的 SQL 脚本

PHP array_push() 不起作用,但 array[] 起作用,只是没有 SQL where 子句

visual-studio - 项目文件不完整,在更新的 Visual Studio 2017 上找不到 NETCore.App 2.1

java - 是否可以将 Visual Studio 用作 Google Web Toolkit 的 IDE?