日期:2014-05-18  浏览次数:20432 次

vs2008自带数据库,与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误。error: 26
我使用的是VS2008自带的数据库,然后又安装了SQL Server Management Studio Express。我修改成为数据库SqlServer和windows身份验证模式。启用sa,并创建了密码,把服务重新启动了一遍。在外围配置器当中,远程连接采用了同时采用TCP/ip和name pipes(B).我就是修改了这写部分,其他的都没有。我开始使用一个小文件做测试。
下面是asp.net代码
aspx当中的代码
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="date.aspx.cs" Inherits="date" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title></title>
</head>
<body>
  <form id="form1" runat="server">
  <div>
   
  <asp:GridView ID="my" runat="server" AutoGenerateColumns="False" 
  BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" 
  CellPadding="3" ForeColor="Black" GridLines="Vertical" 
  >
  <Columns>
  <asp:BoundField DataField="id" HeaderText="ID" />
  <asp:BoundField DataField="name" HeaderText="名字" />
  <asp:BoundField DataField="miaoshu" HeaderText="描述" />
  </Columns>
  <FooterStyle BackColor="#CCCCCC" />
  <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
  <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
  <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
  <AlternatingRowStyle BackColor="#CCCCCC" />
  </asp:GridView>
   
  </div>
  </form>
</body>
</html>
下面是aspx.cs当中的代码
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.SqlClient;
public partial class date : System.Web.UI.Page
{
  protected void Page_Load(object sender, EventArgs e)
  {
  string strconn = " data source=localhost\\SOLEXPRESS;initial catalog=Northwind;" + "user id=sa;password=mxsa";
  SqlConnection myconn = new SqlConnection(strconn);
  string strsql = "SELECT TOP 5 CategorlyID,CotegiryName,Description FROM Categories";
  SqlCommand myCommand = new SqlCommand(strsql, myconn);
  myconn.Open();
  my.DataSource = myCommand.ExecuteReader();
  my.DataBind();
  myconn.Close();

  }
 
}
当我调试的,出现一下错误提示
在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误。未找到或无法访问服务器。请验证实例名称是否正确并且 SQL Server 已配置为允许远程连接。 (provider: SQL 网络接口, error: 26 - 定位指定的服务器/实例时出错)

------解决方案--------------------
防火墙把 1433端口设为例外
------解决方案--------------------
换换连接串试试
1、
string strconn = " data source=.\\SOLEXPRESS;initial catalog=Northwind;" + "user id=sa;password=mxsa";
2、
string strconn = " data source=ip\\SOLEXPRESS;initial catalog=Northwind;" + "u