![](/img/trans.png)
[英]ASP.NET Error System.ComponentModel.Win32Exception: 'The system cannot find the file specified'
[英]My database system cannot find the file specified in asp.net
我正在尝试使用以下代码从数据库检索数据:
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();
}
}
}
}
}
抛出错误:
该系统找不到指定的文件
我想知道是否有人可以告诉我错误出在哪里或指导我进行调试。 提前致谢。
(更新):更具体地说,scon.Open()导致错误:
消息=建立与SQL Server的连接时发生与网络相关或特定于实例的错误。 服务器未找到或无法访问。 验证实例名称正确,并且已将SQL Server配置为允许远程连接。 (提供者:命名管道提供程序,错误:40-无法打开与SQL Server的连接)
这看起来很容易修复,但是我对数据库不是很好。 任何帮助将不胜感激。
我不知道您已经安装了什么SQL Server版本,以及您称它为什么(作为实例名称).....
转到Start > SQL Server > Configuration Tools > Configuration Manager
; 在“ SQL Server Services
,搜索SQL Server
服务-它的名称是什么?
如果是SQL Server (SQLEXPRESS)
,则表示您拥有Express版本,实例名称为SQLEXPRESS
将连接字符串更改为:
Data Source=.\SQLEXPRESS;Initial Catalog=populate;Integrated Security=true;
如果是SQL Server (MSSQLSERVER)
那么您真的应该没问题 -您有一个未命名的默认实例...。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.