'CITY' is not a recognized optimizer lock hints option

Please support our MS SQL advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Sep 2006
Posts: 88
Reputation: bajanpoet is an unknown quantity at this point 
Solved Threads: 0
bajanpoet bajanpoet is offline Offline
Junior Poster in Training

'CITY' is not a recognized optimizer lock hints option

 
0
  #1
Jan 27th, 2009
I have created two table valued multi-statement functions using SQL Server 2000 and am now trying to develop a VB.NET front end application where I run the functions and pass string parameters to them.

Below is a code fragment for one of the functions.

  1. CREATE FUNCTION ViewCustomers(@Region VARCHAR(6))
  2. RETURNS @CustTable TABLE (CustomerID VARCHAR(20), [Customer Name] VARCHAR(50))
  3. AS
  4. BEGIN
  5. IF @Region = 'West'
  6. BEGIN
  7. INSERT @CustTable
  8. SELECT RTRIM(idcust)[Customer ID],
  9. RTRIM(namecust)[Customer Name]
  10. FROM arcus
  11. WHERE idcust IN
  12. ('4000229', '4002100', '60000', '41700', '98850', 'T00038',
  13. '7422', 'S00046', '0092375', '0109550', '94770', '0032250',
  14. 'S00049', '4001118', 'H06830', 'P00060', '5258', '3655',
  15. '3745', 'SS1107', '5127', '4001820', '4000926', 'SS1108',
  16. 'R02430', 'P00048', '4002171', '4001506', 'ZF0017',
  17. 'E00038', 'J00017', 'R06004', '4000500', 'ZC0060',
  18. 'C15093', 'ZS0076')
  19. END
  20. ELSE IF @Region = 'South'
  21. BEGIN
  22. INSERT @CustTable
  23. SELECT RTRIM(idcust)[Customer ID],
  24. RTRIM(namecust)[Customer Name]
  25. FROM arcus
  26. WHERE idcust IN
  27. ('G00088' ,'4000360', '4008005', '4001892', 'D04905',
  28. 'ZA0009', '4000310', 'D04895', 'E00041', 'E00014',
  29. 'E00024', '7643', '4000850', '73500', '4000935',
  30. '4000936', '4001300', '86100', 'P00059', 'P00031', '4665',
  31. '4002043', '4001444', '0098690', '1082', '98900',
  32. 'S00051', '4342', 'SS1104', '17800', '110400', '1094',
  33. '4002041', '0092000', '4470', 'ZI0001', '0025300',
  34. 'ZC0100', 'ZF0035', 'R06010')
  35. END
  36. ELSEIF.....
  37. ....
  38. END

When I run the function in SQL Server Query Analyzer, using SELECT * FROM ViewCustomers('City') it works and displays the customerID and name of the customers associated with the region passed to the function as a parameter.

My next step is to run the function through VB.NET using this code

  1. Private Sub ViewCustomers()
  2. conn.Open()
  3. Dim SQLComm = New SqlCommand("SELECT * FROM ViewCustomers(" & vRegion & ")", conn)
  4. Dim r As SqlDataReader()
  5. r = SQLComm.ExecuteReader()
  6. dgCustomers.DataSource = r
  7. conn.Close()
  8. End Sub

So when I'm trying to run the solution to test the code, the error pointer points to the r = SQLComm.ExecuteReader() line and I get the error ''CITY' is not a recognized optimizer lock hints option". I'm trying to populate a datagrid with data in the function's @CustTable.


How do I get rid of this Optimizer lock hints option error?

(BTW - the original request was placed in the VB.NET forum because the error was in the r = SQLComm.ExecuteReader() line, but I was advised to try here as well.)
Last edited by bajanpoet; Jan 27th, 2009 at 9:16 am. Reason: Making sure the formatting was right.
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2,065
Reputation: Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice 
Solved Threads: 256
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Postaholic

Re: 'CITY' is not a recognized optimizer lock hints option

 
1
  #2
Jan 27th, 2009
If you traced the SQL Command sent, you'll find it doesn't surround the state within single quotes '
What you need is to modify it
Dim SQLComm = New SqlCommand("SELECT * FROM ViewCustomers('" & vRegion & "')", conn)
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 88
Reputation: bajanpoet is an unknown quantity at this point 
Solved Threads: 0
bajanpoet bajanpoet is offline Offline
Junior Poster in Training

Re: 'CITY' is not a recognized optimizer lock hints option

 
0
  #3
Jan 27th, 2009
wow... I didn't see that... you're right! I'll modify it and get back to you... give me a sec...
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 88
Reputation: bajanpoet is an unknown quantity at this point 
Solved Threads: 0
bajanpoet bajanpoet is offline Offline
Junior Poster in Training

Re: 'CITY' is not a recognized optimizer lock hints option

 
0
  #4
Jan 27th, 2009
I seem to have gotten past that problem... now it says
  1. InvalidCastException
  2. Unable TO cast object of type 'System.Data.SqlClient.SqlDataReader' TO type 'System.Data.SqlClient.SqlDataReader[]'.'
  3.  
looking at the same ExecuteReader command r = SQLComm.ExecuteReader()
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2,065
Reputation: Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice 
Solved Threads: 256
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Postaholic

Re: 'CITY' is not a recognized optimizer lock hints option

 
0
  #5
Jan 27th, 2009
It works fine
  1. Dim r As SqlClient.SqlDataReader
  2. r = SQLComm.ExecuteReader()
  3. dgCustomers.DataSource = r
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2,065
Reputation: Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice 
Solved Threads: 256
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Postaholic

Re: 'CITY' is not a recognized optimizer lock hints option

 
0
  #6
Jan 27th, 2009
Please mark both threads as solved, if it's
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 88
Reputation: bajanpoet is an unknown quantity at this point 
Solved Threads: 0
bajanpoet bajanpoet is offline Offline
Junior Poster in Training

Re: 'CITY' is not a recognized optimizer lock hints option

 
0
  #7
Jan 27th, 2009
I will... thanks!

Should I post another question concerning why the datagrid isn't showing up the data from the function, or should I ask it here?
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2,065
Reputation: Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice 
Solved Threads: 256
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Postaholic

Re: 'CITY' is not a recognized optimizer lock hints option

 
0
  #8
Jan 27th, 2009
Another thread because we can made a reference to this if anyone has a problem calling UDF in VB.NET
Last edited by Ramy Mahrous; Jan 27th, 2009 at 4:00 pm.
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 88
Reputation: bajanpoet is an unknown quantity at this point 
Solved Threads: 0
bajanpoet bajanpoet is offline Offline
Junior Poster in Training

Re: 'CITY' is not a recognized optimizer lock hints option

 
0
  #9
Jan 27th, 2009
ok thanks .... here we go...
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2,065
Reputation: Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice 
Solved Threads: 256
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Postaholic

Re: 'CITY' is not a recognized optimizer lock hints option

 
0
  #10
Jan 27th, 2009
DataGrid and such programming related, should be asked in VB.NET forum, friend.
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC