Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am using SQL Server in a Vb.net program and when I try to specify an index with an ExecuteReader command that should be used, I get an error message about forceplan. I would like to use the index since it gives the best access. How do i force forceplan to be 'on' ?

What I have tried:

I open the database as follows:
VB.NET
conLocDb = New System.Data.SqlClient.SqlConnection
cmdLocDb = New System.Data.SqlClient.SqlCommand
conLocDb.ConnectionString = "Server=" + strLocDbDatasource + ";Database=" +
strLocDbDefaultcoll + ";Trusted_Connection=True;"
cmdLocDb.CommandTimeout = 0
conLocDb.Open()
cmdLocDb.Connection = conLocDb

Then my read is as follows:
VB.NET
cmdLocDb.CommandText = "Select IcData From Iscode with(index(Iscode01))" +
"Where IcCodt = 'GLSI' " +
"and IcCode = '" + Format(intCity, "000") + " SCOASO' " +
"and IcLang = 0 " +
"and IcAudl = 0"
Reader = cmdLocDb.ExecuteReader()

System.Data.SqlClient.SqlException:
Query processor could not produce a query plan because of the hints defined in this query. Resubmit the query without specifying any hints and without using SET FORCEPLAN

I have to remove the 'with(index...' for it to run, but would like to specify the index

So the question is where can I specify the 'forceplan' set ?
Posted
Updated 22-Nov-23 23:02pm
v3

1 solution

 
Share this answer
 
Comments
Member 16146638 23-Nov-23 4:07am    
Thanks Richard, but i have to specify it in VB code - that is the real problem
Richard Deeming 23-Nov-23 4:17am    
No, the real problem is that you haven't shown us any of your code, or the exception message, or any real details of the problem.

Click the green "Improve question" link and update your question to include those missing details.
Member 16146638 23-Nov-23 4:25am    
I open the database as follows:
conLocDb = New System.Data.SqlClient.SqlConnection
cmdLocDb = New System.Data.SqlClient.SqlCommand
conLocDb.ConnectionString = "Server=" + strLocDbDatasource + ";Database=" +
strLocDbDefaultcoll + ";Trusted_Connection=True;"
cmdLocDb.CommandTimeout = 0
conLocDb.Open()
cmdLocDb.Connection = conLocDb

Then my read is as follows:
cmdLocDb.CommandText = "Select IcData From Iscode with(index(Iscode01))" +
"Where IcCodt = 'GLSI' " +
"and IcCode = '" + Format(intCity, "000") + " SCOASO' " +
"and IcLang = 0 " +
"and IcAudl = 0"
Reader = cmdLocDb.ExecuteReader()

I have to remove the 'with(index...' for it to run, but would like to specify the index
So the question is where can i specify the 'forceplan' set ?
Richard MacCutchan 23-Nov-23 4:40am    
Sorry, I have not used this feature; you will need to find examples elsewhere.
Richard Deeming 23-Nov-23 4:42am    
And the error message you get is?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900