网页提交数据到数据库,用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