如何使用ASP.NET连接数据库 [英] how to connect database using ASP.NET

查看:87
本文介绍了如何使用ASP.NET连接数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码..我只是检查天气数据库是否连接...





< asp:按钮ID =Button1runat =serverText =Buttononclick =Button1_Click/>



------------ --------

This is my code.. Im just checking weather database connected or not...


<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click"/>

--------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient;


namespace dbc
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string connectionString="Data Source=USER-PC;Initial Catalog=master;Integrated Security=True";
            SqlConnection conn=new SqlConnection(connectionString);
            conn.Open();
            Response.Write("hi");
            conn.Close();
        }
    }
}





------------ ----

但是我得到了这样的错误......我怎么能解决这个错误..



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



----------------
But i got the error like this... how can i resolve this error..

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)

推荐答案

检查此answer [ ^ ]


这篇关于如何使用ASP.NET连接数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆