关于存储过程的奇怪的问题!!!请帮我解决一下!!!

chengqin2009 2010-01-06 10:48:43
我在usersinformation.aspx 调用users类中的personinformation()方法,此方法是用户登录之后,根据用户名查询用户的所有信息,此方法中调用存储过程userinformation。可是很奇怪的是每次到usersinformation.aspx 页面时,总是出错,提示存储过程userinformation不存在,我明明在数据库中建立了此存储过程,回数据库一看,这个存储过程竟然没有了。我再重新建,重新运行页面,又是这样的!请帮我解决一下吧!
personinformation()方法
public DataRow personinformation(string uid)
{
SqlConnection con =new SqlConnection (constring);
con.Open();
//创建SqlDataAdapter对象,并调用userinformation存储过程
SqlDataAdapter sda=new SqlDataAdapter("userinformation",con);
//设定sda对象要执行命令的类型
sda.SelectCommand.CommandType=CommandType.StoredProcedure;
//添加参数并设定参数的值
sda.SelectCommand.Parameters.Add("@uid",SqlDbType.VarChar,50).Value=uid;
//创建数据集
DataSet ds=new DataSet();
try
{
//填充数据集合
sda.Fill(ds);
//返回数据集中数据行
return ds.Tables[0].Rows[0];
}
catch(Exception error)
{
throw new System.Exception(error.Message );
}
finally
{
con.Close();
}
}

--userinformation存储过程,查询用户信息
create proc userinformation
@uid varchar(50)
as
select * from users where u_id=@uid
...全文
247 23 打赏 收藏 转发到动态 举报
写回复
用AI写文章
23 条回复
切换为时间正序
请发表友善的回复…
发表回复
chengqin2009 2010-01-06
  • 打赏
  • 举报
回复
没有啊 账户是相同的,我前面有个插入的存储过程就是可以用的
newdigitime 2010-01-06
  • 打赏
  • 举报
回复
会不会是你建存储时所用的数据库帐户
与代码 中连接字符串的帐户不同?
vip__888 2010-01-06
  • 打赏
  • 举报
回复
看不出问题
polarissky 2010-01-06
  • 打赏
  • 举报
回复
数据库qnwz中如果有存储过程userinformation的话,就实在想不出问题在哪儿了?期待高人指点
polarissky 2010-01-06
  • 打赏
  • 举报
回复
305321377
chengqin2009 2010-01-06
  • 打赏
  • 举报
回复
我的数据库连接字符串
<add name="qnwzConnectionString" connectionString="Data Source=CHENGQIN-PC\SQLEXPRESS;Initial Catalog=qnwz;Integrated Security=True"
providerName="System.Data.SqlClient" />
要是我的字符串连接的不是我建的库的话,怎么会影响我所建数据库呢?能不能加你QQ啊?
polarissky 2010-01-06
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 chengqin2009 的回复:]
我确定存储过程是建在我自己的数据库里的,之前有个存储过程就是能正确执行的
[/Quote]
我跑了你写的那个方法:
public DataRow personinformation(string uid)
{
string constring = @"Data Source=(local)\SQLEXPRESS;Initial Catalog=aspnetdb;User ID=sa;Password=123456;";
SqlConnection con = new SqlConnection(constring);
con.Open();
//创建SqlDataAdapter对象,并调用userinformation存储过程
SqlDataAdapter sda = new SqlDataAdapter("userinformation", con);
//设定sda对象要执行命令的类型
sda.SelectCommand.CommandType = CommandType.StoredProcedure;
//添加参数并设定参数的值
sda.SelectCommand.Parameters.Add("@uid", SqlDbType.VarChar, 50).Value = uid;
//创建数据集
DataSet ds = new DataSet();
try
{
//填充数据集合
sda.Fill(ds);
//返回数据集中数据行
return ds.Tables[0].Rows[0];
}
catch (Exception error)
{
throw new System.Exception(error.Message);
}
finally
{
con.Close();
}
}

没有任何问题的。
我是希望楼主确认,你使用数据库连接字符串(我这里是Data Source=(local)\SQLEXPRESS;Initial Catalog=aspnetdb;User ID=sa;Password=123456;)的数据库名字(我这是aspnetdb)跟存储过程所在数据库名字(我这是aspnetdb)相同。
chengqin2009 2010-01-06
  • 打赏
  • 举报
回复
呜呜 我照着xinsiyu2008的代码改了 还是同样的问题
chengqin2009 2010-01-06
  • 打赏
  • 举报
回复
我确定存储过程是建在我自己的数据库里的,之前有个存储过程就是能正确执行的
csdnfan 2010-01-06
  • 打赏
  • 举报
回复
改成如下试一试

SqlCommand command = new SqlCommand("userinformation", con);
command.CommandType=CommandType.StoredProcedure;
SqlDataAdapter SqlDataAdapter = new SqlDataAdapter(command);

polarissky 2010-01-06
  • 打赏
  • 举报
回复
楼主,你的代码和存储过程没问题。我刚跑了一遍,成功。我也怀疑你的存储过程所在的数据库是不是跟数据库连接字符串使用的数据库相同。请核查一下。
okidasougo 2010-01-06
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 zhouyanfss 的回复:]
给你个例子吧
SQL codeUSE[ZA]GO/****** 对象: StoredProcedure [dbo].[SelectVisitors] 脚本日期: 01/06/2010 10:56:18 ******/SET ANSI_NULLSONGOSET QUOTED_IDENTIFIERONGOCREATEPROCEDURE[dbo].[SelectVisitors]ASSET NOCOUNTON;SELECT ID, LevelMarkID, logonLevelID, segmentID, timeID, newVisits, returnVisits, Visitors, newPageViews, returnPageViews, newTimeOnSite, returnTimeOnSite, newBounces, returnBouncesFROM dbo.visitors
另外我怀疑你创建时,没有选择数据库吧?你是不是创建到系统库去了!!!默认是master的
[/Quote]
同感
tzs2304 2010-01-06
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 zhouyanfss 的回复:]
给你个例子吧
SQL codeUSE[ZA]GO/****** 对象: StoredProcedure [dbo].[SelectVisitors] 脚本日期: 01/06/2010 10:56:18 ******/SET ANSI_NULLSONGOSET QUOTED_IDENTIFIERONGOCREATEPROCEDURE[dbo].[SelectVisitors]ASSET NOCOUNTON;SELECT ID, LevelMarkID, logonLevelID, segmentID, timeID, newVisits, returnVisits, Visitors, newPageViews, returnPageViews, newTimeOnSite, returnTimeOnSite, newBounces, returnBouncesFROM dbo.visitors
另外我怀疑你创建时,没有选择数据库吧?你是不是创建到系统库去了!!!默认是master的
[/Quote]
up
huangwenquan123 2010-01-06
  • 打赏
  • 举报
回复
using (SqlConnection conn = new SqlConnection())
{
string str = "proc_Select"; //存储过程名称
conn.ConnectionString = ConfigurationManager.ConnectionStrings["StudentConnections"].ConnectionString; //连接字符串
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = str;
cmd.Connection = conn;
conn.Open();
Repeater1.DataSource = cmd.ExecuteReader();
Repeater1.DataBind();
}
我的存储过程和你差不多
仅供参考
zhouyanfss 2010-01-06
  • 打赏
  • 举报
回复
给你个例子吧
USE [ZA]
GO
/****** 对象: StoredProcedure [dbo].[SelectVisitors] 脚本日期: 01/06/2010 10:56:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[SelectVisitors]
AS
SET NOCOUNT ON;
SELECT ID, LevelMarkID, logonLevelID, segmentID, timeID, newVisits, returnVisits, Visitors, newPageViews, returnPageViews, newTimeOnSite, returnTimeOnSite, newBounces, returnBounces FROM dbo.visitors

另外我怀疑你创建时,没有选择数据库吧?你是不是创建到系统库去了!!!默认是master的
chengqin2009 2010-01-06
  • 打赏
  • 举报
回复
是的!
yan267 2010-01-06
  • 打赏
  • 举报
回复
回数据库一看,这个存储过程竟然没有了。我再重新建,重新运行页面,又是这样的!

存储过程被删除了??
chengqin2009 2010-01-06
  • 打赏
  • 举报
回复
有点丢人,我的数据表建的有问题,现在这个页面能运行了,谢谢每个人热心人
nick_so 2010-01-06
  • 打赏
  • 举报
回复
我试了你的代码,能够正常执行,存储过程也在.
同意楼上,设断点,看看是不是 周期后的其他事件触发了数据库删除操作.
csdnfan 2010-01-06
  • 打赏
  • 举报
回复
楼上啊,你说存储过程会被删,感觉好奇怪哦,你执行完后是怎么查到存储过程被删了呢?sp_helptext userinformation吗?可以在数据库中跟踪一下是不是有什么触发器啊?
加载更多回复(3)

62,266

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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