bingbing4736 于 2015.06.11 17:13 提问
- aspx网页提交数据到SQL server数据库执行存储程序超时
-
网页提交数据到数据库,用giridview显示数据,查询的数据源数据库特别大,查询时间较长,最后反馈页面是服务超时,怎么解决?
protected void Button1_Click(object sender, EventArgs e)
{
string connstr = ConfigurationManager.ConnectionStrings["connstr"].ConnectionString;
SqlConnection myConn = new SqlConnection(connstr);
myConn.Open();
{
if (myConn.State == ConnectionState.Open)
{
SqlCommand comm = new SqlCommand();comm.Connection = myConn; //comm.CommandTimeout = 120; comm.CommandType = CommandType.StoredProcedure; comm.CommandText = "SearchTitle"; SqlParameter Title = new SqlParameter("@Title", SqlDbType.Char, 128); Title.Value = TextBox1.Text; comm.Parameters.Add(Title); SqlDataAdapter da = new SqlDataAdapter(comm); DataTable dt = new DataTable(); da.Fill(dt); GridView1.DataSource = dt; GridView1.DataBind(); } } myConn.Close(); } 这是后台代码 以下是存储程序: IF object_id('temp0..TitleSearch') is not null BEGIN delete from temp0.dbo.TitleSearch END
declare @DatabaseNameNum varchar(256)
declare @x int
set @x=1
while(@x<12)
begin
set @DatabaseNameNum = 'QunInfo'+cast(@x as varchar)
set @x=@x+1
print @DatabaseNameNum
--end
--循环查询QunInfo1至QunInfo11数据库declare @sql2 varchar(max) declare @i int=0 IF object_id('temp0..temp0_test') is not null BEGIN DROP TABLE temp0..temp0_test create table temp0..temp0_test(id int identity(1,1),name nvarchar(1000)) END --declare @tb table(id int identity(1,1),name nvarchar(1000)) set @i = 1 set @sql2=' insert into temp0..temp0_test(name) select t.name from @DatabaseNameNum.sys.tables t where t.name like ''Q%'' ' set @sql2=REPLACE(@sql2,'@DatabaseNameNum',@DatabaseNameNum)--变量替换 print @sql2 exec(@sql2)
--查询以Q开头的所有表
declare @sql1 varchar(max) declare @tb_name nvarchar(100) while @i <= cast((select COUNT(*) from temp0..temp0_test) as int) begin select @tb_name = @DatabaseNameNum +'.dbo.'+ name from temp0..temp0_test where id = @i ; --SET IDENTITY_INSERT ON --SET IDENTITY_INSERT OFF set @sql1='insert into Title([QunNum] ,[MastQQ] ,[CreateDate] ,[Title] ,[Class] ,[QunText] ) select [QunNum] ,[MastQQ] ,[CreateDate] ,[Title] ,[Class] ,[QunText] from @tb_name with(index(keywords))where Title like ''%@Title%'' ' set @sql1=REPLACE(@sql1,'@tb_name',@tb_name) set @sql1=REPLACE(@sql1,'@Title',@Title) exec(@sql1) print @sql1 set @i = @i + 1 end
--将检索到的数据插入到新表
end
select * from Title
-
-
bulusli3
2015.06.11 17:17
分页显示,一次显示几十条。
-
- bingbing4736 不是显示的数据多,是要查询的数据源内容多,查出的结果也许并不多
- 接近 3 年之前 回复
-
- huang_huang118 2015.06.11 17:16
具体问题具体分析,如果是远程服务器,看看是不是线路故障、服务器故障……
如果是本地,看看是不是配置问题……
-
- bingbing4736 本地服务器,无故障,查询其他数据没问题
- 接近 3 年之前 回复
-
-
Tiger_Zhao
2015.06.11 17:17
要分页,一次处理数据不要太多。
-
- bingbing4736 不是显示的数据多,是要查询的数据源内容多,查出的结果也许并不多
- 接近 3 年之前 回复
-
-
u012216727
2015.06.11 18:24
写存储过程,或者你写的sql语句需要优化一下;
-
-
oyljerry
2015.06.11 22:17
主要就是数据库查询优化,或者降低存储过程做的事,把数据简单返回,由客户端处理,减少存储过程做的工作。
-
- wokaonimama 2015.06.11 22:45
把你查询语句 写出来