我的数据库系统找不到在asp.net中指定的文件 [英] My database system cannot find the file specified in asp.net

查看:165
本文介绍了我的数据库系统找不到在asp.net中指定的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下代码从数据库中检索数据:

I am trying to retrieve data from a database with the following code:

public partial class populate : System.Web.UI.Page
{
    SqlConnection scon = new SqlConnection("Data Source = localhost; Integrated Security = true; Initial Catalog = populate");  

    protected void Page_Load(object sender, EventArgs e) {     
        StringBuilder htmlString = new StringBuilder(); 

        if(!IsPostBack)
        {
            using (SqlCommand scmd = new SqlCommand())
            {
                scmd.Connection = scon;
                scmd.CommandType = CommandType.Text;
                scmd.CommandText = "SELECT * FROM populate";

                scon.Open();

                SqlDataReader articleReader = scmd.ExecuteReader();

                htmlString.Append("'Populate page:'");                

                if (articleReader.HasRows)
                {
                    while (articleReader.Read())
                    {
                        htmlString.Append(articleReader["dateTime"]);
                        htmlString.Append(articleReader["firstName"]);
                        htmlString.Append(articleReader["lastName"]);
                        htmlString.Append(articleReader["address"]);
                        htmlString.Append(articleReader["details"]);                       
                    }
                    populatePlaceHolder.Controls.Add(new Literal { Text = htmlString.ToString() });
                    articleReader.Close();
                    articleReader.Dispose();
                }
            }
        }
    }
}

抛出错误:

系统找不到指定的文件

The system cannot find the file specified

我想知道是否有人可以告诉我错误出在哪里或指导我进行调试.预先感谢.

I am wondering if someone can show me where the error is or guide me through debugging this. Thanks in advance.

(更新):更具体地说,scon.Open()导致错误:

(update): More specifically, the scon.Open() is causing the error:

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

Message=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)

这看起来很容易修复,但是我对数据库不是很好.任何帮助将不胜感激.

This looks easy enough to fix, but I'm not very good with the database. Any help will be appreciated.

推荐答案

我不知道您安装了什么SQL Server版本,以及您称之为什么(作为实例名称).....

I don't know what SQL Server edition you have installed, and what you called it (as an instance name) .....

转到开始>SQL Server>配置工具>配置管理器;在 SQL Server服务下,搜索 SQL Server 服务-它的名字是什么?

Go to Start > SQL Server > Configuration Tools > Configuration Manager; under SQL Server Services, search for the SQL Server service - what is it's name??

如果它是 SQL Server(SQLEXPRESS),则表示您拥有Express版本,实例名称为 SQLEXPRESS -将连接字符串更改为:

If it's SQL Server (SQLEXPRESS), then that means you have the Express edition, with an instance name of SQLEXPRESS - change your connection string to:

Data Source=.\SQLEXPRESS;Initial Catalog=populate;Integrated Security=true; 

如果它是 SQL Server(MSSQLSERVER),那么您应该没事-您有一个未命名的默认实例....

If it's SQL Server (MSSQLSERVER) then you should be fine really - you have an unnamed, default instance ....

这篇关于我的数据库系统找不到在asp.net中指定的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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