sql server - When I run a C# parameterized query, it times out. Same query with hard-coded parameters works fine -
i want ids text column contains string filter.
when run parameterized query, times out:
sqlcommand cmd = new sqlcommand("select id tablename text @filter", conn); if (filter != null) { cmd.parameters.addwithvalue("@filter", "%" + filter + "%"); sqldatareader reader; reader = cmd.executereader(); //locks here! }
when run same code, hard-coded search parameters, returns in timely manner results wanted:
sqlcommand cmd = new sqlcommand("select id tablename text '%patterntomatch%'", conn); sqldatareader reader; reader = cmd.executereader();
in ways 2 queries differ? think parameterization doing more simple text replacement.
clarification: i'm talking microsoft sql server 2012 server.
new information: times out when search filter longer 6 characters.
edit: solved! set search stored procedure:
create procedure textsearch @filter varchar(max) = '' begin set nocount on; select distinct id tablename [text] '%' + @filter + '%' end go
when using paramaterized queries operator, need single quote wildcard character:
new sqlcommand("select id tablename text '%' + @filter + '%' ", conn);
then add together parameter usual:
cmd.parameters.addwithvalue("@filter", filter);
c# sql-server
No comments:
Post a Comment