这次代码全贴上,请大家看看什么错误!!

sun_cathay 2003-05-23 11:53:14
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace WebApplication5
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox txtname;
protected System.Web.UI.WebControls.TextBox txtpassword;
protected System.Web.UI.WebControls.TextBox txtrepassword;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.HtmlControls.HtmlGenericControl Message;
protected System.Web.UI.WebControls.RequiredFieldValidator rfvName;
protected System.Web.UI.WebControls.RequiredFieldValidator rfvpassword;
protected System.Web.UI.WebControls.RequiredFieldValidator rfvrepassword;
protected System.Web.UI.WebControls.RequiredFieldValidator rfvemail;
protected System.Web.UI.WebControls.RegularExpressionValidator revemail;
protected System.Web.UI.WebControls.TextBox txtemail;


SqlConnection myconn;


private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
//连接数据库
//string strconn="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=nettest;Data Source=(local);Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=SUNFX;Use Encryption for Data=False;Tag with column collation when possible=False";
string strconn = "Provider=SQLOLEDB.1;Persist Security Info=True;User ID=sa;Initial Catalog=pubs;Data Source=Sunfx;Packet Size=4096";
myconn= new SqlConnection(strconn);
myconn.Open();

}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void Button1_Click(object sender, System.EventArgs e)
{

string strsql;
strsql="select * from zhuce where username='"+txtname.Text+"'";
SqlCommand mycommand=new SqlCommand(strsql,myconn);
//用reader对象来查询用户名是否已经存在
SqlDataReader reader=mycommand.ExecuteReader();
if (reader.Read())
{
Message.InnerHtml="<p align=center><b>该用户已经存在!</b>";
reader.Close();
}
else
{
reader.Close();
strsql="INSERT INTO zhuce VALUES('"+txtname.Text+"','"+txtpassword.Text+"','"+txtemail.Text+"')";
mycommand=new SqlCommand(strsql,myconn);
mycommand.ExecuteNonQuery();
Message.InnerHtml="<p align=center><b>注册成功!</b>";
}
myconn.Close();
}
}
}
错误提示:

连接字符串 provider 中未知的连接选项。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.ArgumentException: 连接字符串 provider 中未知的连接选项。

源错误:


行 41: //string strconn="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=nettest;Data Source=(local);Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=SUNFX;Use Encryption for Data=False;Tag with column collation when possible=False";
行 42: string strconn = "Provider=SQLOLEDB.1;Persist Security Info=True;User ID=sa;Initial Catalog=pubs;Data Source=Sunfx;Packet Size=4096";
行 43: myconn= new SqlConnection(strconn);
行 44: myconn.Open();
行 45:


源文件: d:\inetpub\wwwroot\webapplication5\webform1.aspx.cs 行: 43

堆栈跟踪:


[ArgumentException: 连接字符串 provider 中未知的连接选项。]
System.Data.SqlClient.ConStringUtil.ParseStringIntoHashtable(String conString, Hashtable values)
System.Data.SqlClient.ConStringUtil.ParseConnectionString(String connectionString)
System.Data.SqlClient.SqlConnection.set_ConnectionString(String value)
System.Data.SqlClient.SqlConnection..ctor(String connectionString)
WebApplication5.WebForm1.Page_Load(Object sender, EventArgs e) in d:\inetpub\wwwroot\webapplication5\webform1.aspx.cs:43
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()


...全文
23 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
waterass 2003-05-23
  • 打赏
  • 举报
回复
可能是密码和字符串各式的问题,试试我的连接字符串。




string strconn="server=(local);database=pubs;user id=sa;password=7941978epe";

把password换成你的sa 的密码,把pubs换成你要连的数据库,(是nettest吗?)
你的字符串有一些应该没什么用,把没用的都去掉。
还有应该把sa 的密码加上!

timmy3310 2003-05-23
  • 打赏
  • 举报
回复
你的连接字符串是OleDb的,SqlClient不需要指明Provider,改成:

string strconn = "Server=(local);Database=pubs;User ID=sa;Password=password";

试试

不行的话,用VS.Net设计器生成一个SqlClient的连接串
zwztu 2003-05-23
  • 打赏
  • 举报
回复
你在vs.net中能连上sqlserver吗?如果能连上,将连接字符串拷过来即可。
jinye 2003-05-23
  • 打赏
  • 举报
回复
上面的v1.1.4322是v1.0.3705
jinye 2003-05-23
  • 打赏
  • 举报
回复
运行C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_regiis.exe -i

路径可能不一样,你装那里找那里。
sim 2003-05-23
  • 打赏
  • 举报
回复
这个问题我昨天刚遇到,将connectstring改为:"server=localhost;uid=sa;pwd=;database=yourdatabase"

110,570

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧