注册 登录
编程论坛 ASP.NET技术论坛

数据库连接出了问题!!sql server2000的

dengjifu 发布于 2007-10-29 12:37, 1277 次点击

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

namespace AdoNetObject
{
/// <summary>
/// Summary description for Connection.
/// </summary>
public partial class Connection : System.Web.UI.Page
{
private String ConnectionString = "data source=dengjifu;Database=jwgl;uid=fu;pwd=5591960;";

protected void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
ConnectionObject();
}
}

private void ConnectionObject()
{
SqlConnection sqlConnection = new SqlConnection(ConnectionString);
sqlConnection.Open();
Response.Write("<script>alert('" + sqlConnection.ConnectionString.Replace(";", "\\n") + "\\n数据库的连接成功!!!');</script>");
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
}
#endregion
}
}

在建立与服务器的连接时出错。在连接到 SQL Server 2005 时,在默认的设置下 SQL Server 不允许进行远程连接可能会导致此失败。 (provider: TCP 提供程序, error: 0 - 由于目标机器积极拒绝,无法连接。)

10 回复
#2
bygg2007-10-29 12:55

在连接外面加个try..catch..吧.你确定你连接的是SQL2000,你装过2005吧?

#3
dengjifu2007-10-29 14:49
都是出现那样的错误啊!!我没装过2005。
#4
洁洁2007-10-29 15:21
你的数据库和服务器的数据库连好了吗?
#5
dengjifu2007-10-29 17:21
我本地机试
#6
魔城侠客2007-10-29 17:45

把uid=fu这个帐号隶属于admin里看看

#7
chashen88882007-10-29 18:58
把dengjifu改成localhost看看
#8
jaychang2007-10-29 21:55

重新生成项目试试!

#9
guoxhvip2007-10-29 22:55
把连接串改成server = .; uid = 用户名; pwd = 密码; database = 数据库 试试
#10
baoguoping2007-10-30 09:58

我顶.最好是在本机上试下看连接是否有问题.data source=.这样改下试下

#11
zhaomin1232007-10-31 09:37

你不用SQL的混合模式,用WINDOWS验证模式试试看,这样也许就可以了。我的以前也有这种问题
sqlconnection mycon="server=localhost;database=DatabaseName;integrated security=SSPI";

这样也许就可以了,试试兄弟。

1