跪求VS2005+MSSQL2K能人高手帮帮小弟解决数据库的问题

xutongfu 2008-09-19 09:55:50
我用VS2005+MSSQL2K开发网页,语言用的是C#,数据库连接字符串定义在WEB.Config文件里,如下所示:

<appSettings>
<add key="connstr" value="Data Source=localhost;Initial Catalog=sfstk;Integrated Security=True"/>
</appSettings>
<connectionStrings>
<add name="connstr" connectionString="Data Source=localhost;Initial Catalog=sfstk;Integrated Security=True"/>
</connectionStrings>

程序在VS2005中能够正常运行,但是在IIS中,只要运行与数据操作有关的页面就出错,比如说SqlDataReader sdr=……;

我测试了sdr的值为NULL。

我的数据库是Wwindows的身份验证,操作系统是XP SP2,是不是我的数据库配置不对,还是怎么的,求大家帮帮忙,整了好久都没有解决,急死人了。

...全文
150 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
HYangryPigO_O 2008-12-03
  • 打赏
  • 举报
回复
up
runstone712 2008-09-19
  • 打赏
  • 举报
回复
你用的是2005
iis的asp.net版本是2.0吗?
会不会是版本的问题
LovingAlison 2008-09-19
  • 打赏
  • 举报
回复
问题是他没发布前可以运行的 发布后就不能运行了 这点比较奇怪
xutongfu 2008-09-19
  • 打赏
  • 举报
回复
第二个webconfig.cs应该是webfunction.cs才对!
xutongfu 2008-09-19
  • 打赏
  • 举报
回复
web.config

<appSettings>
<add key="connstr" value="Data Source=localhost;Initial Catalog=sfstk;Integrated Security=True"/>
</appSettings>
<connectionStrings>
<add name="connstr" connectionString="Data Source=localhost;Initial Catalog=sfstk;Integrated Security=True"/>
</connectionStrings>

webconfig.cs

private static void openConnection()
{
if (conn.State == ConnectionState.Closed)
{
conn.ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["connstr"].ConnectionString;//connstr是web.config文件中定义的数据库连接字符串
comm.Connection = conn;
try
{
conn.Open();
}
catch (Exception e)
{
throw new Exception (e.Message);
}
}
}

public static SqlDataReader dataReader(string sqlstr)
{
SqlDataReader dr = null;
try
{
openConnection();
comm.CommandText = sqlstr;
comm.CommandType = CommandType.Text;
dr = comm.ExecuteReader(CommandBehavior.CloseConnection);
}
catch
{
try
{
dr.Close();
closeConnection();
}
catch { }
}
return dr;
}

default.aspx.cs

SqlDataReader sdr=WebFunction.dataReader("select * from [admin] where user_name='"+this.username.Text.Trim() +"' and user_pwd='"+this.userpwd.Text.Trim() +"'");
if (sdr.Read() )
{
this.Label1.Text = "用户不存在或用户密码不正确"}
else
{
Response.Redirect("main.aspx");
}
WebFunction.closeDataReader(ref sdr);
dota_1234 2008-09-19
  • 打赏
  • 举报
回复
重新設置一下虛擬路徑。。。試試看
JeffChung 2008-09-19
  • 打赏
  • 举报
回复
把你的代码贴上来看看
Wesley 2008-09-19
  • 打赏
  • 举报
回复
帮顶,学习一下
xutongfu 2008-09-19
  • 打赏
  • 举报
回复
我用sdr==null来测试,其显示为真。
如果我直接sdr.read(),就提示:System.NullReferenceException: 未将对象引用设置到对象的实例。
贝克汉鸭 2008-09-19
  • 打赏
  • 举报
回复
错误提示什么啊
LovingAlison 2008-09-19
  • 打赏
  • 举报
回复
换成sqlserver认证试试看

110,533

社区成员

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

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

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