I started with this question: (how-to-compare-liststring-to-db-table-using-linq). Using the solution offered there, it worked for my test with only 5 items in my list.
I'm having an issue with this now. I'm getting a SQL error saying "error near 0".
After using a LINQ to SQL visualizer, the problem is when Visual Studio is assigning the numbers in the list to the parameters. It will assign the first 10 just fine.
Once it hit the 11th, it jumps to the number at index 1 and assigns the same number 10 times to different params, but adding a last digit(0-9) to make each one unique. It then moves to the number at index 2 and proceeds to assign that same number multiple times.
It actually runs to the the end of the declared params, but I would imagine if there were 100 params declared it would continue.
var custdata = from c in db.CUSTs
where tnbrs.Contains(c.NPA + c.NXX + c.LINE_NBR)
select new { c.PON, c.PartnerID };
What is going on here?
So apparently its the LINQ to SQL visualizer, procured from Scott Gu's blog, that has the problems with assigning the parameters correctly.
I used this class with the System.Diagnostics to log the the LINQ to SQL debug.
If you use the class above be sure to change the namespace to match the one declared in your project.
Related
I don't want to complicate by giving all details of actual reason for this requirement. Hence, I'll try to give a simple example.
Following is my requirement:
1) Pop out a MessageBox whenever there is a change of value in a table called stock.
2) In simple words, if I run following query in MS SQL:
update stocktable set stockcount = 4 where StockID = 1111
Then, my application should recognize that there is a change in value so it should give me a popup in MessageBox in my application.
I HAVE ALREADY TRIED THE FOLLOWING:
I have been able to achieve this by checking stockcount every second using a timer.
But it's not feasible in terms of performance. Because if say there are 500 users, then on all 500 computers, there will be 500(people) * 12(hours) * 60(minues) * 60(minues) per day.
Hence, the other way I could think of is to invoke function to display MessageBox only when there is a change rather than checking for the change from application every second.
Please help. I am writing this code in Visual Studio using C#. Back-end is MSSQL.
you are interested in what value is changed?
If not you can try something like..
Find the last time table was updated
So these days I am trying to work with the TFS API. So far it was good, but all of a sudden.. I want to retrieve specific story's work items and their respective information using a search by ID method to pick the correct story. In order not to miss some important information I am doing SELECT * in my queries. I get the story, I get the Tasks.. But there seems to be problem with few of the fields - namely AreaPath, IterationPath and Type. As a primitive check I've written down some Console prints to check what's good and what's not - so if I uncomment any of the three previously named on execution this exception is thrown: A first chance exception of type 'Microsoft.TeamFoundation.WorkItemTracking.Client.FieldDefinitionNotExistException' occurred in Microsoft.TeamFoundation.WorkItemTracking.Client.dll.
Here is what I am trying to print out:
Console.WriteLine(target.Fields["Title"].Value);
Console.WriteLine(target.Fields["Description"].Value);
Console.WriteLine(int.Parse(target.Fields["Id"].Value.ToString()));
Console.WriteLine(target.Fields["AreaPath"].Value); //Problem 1
Console.WriteLine(target.Fields["IterationPath"].Value); //Problem 2
Console.WriteLine(int.Parse(target.Fields["AreaId"].Value.ToString()));
Console.WriteLine(int.Parse(target.Fields["IterationId"].Value.ToString()));
Console.WriteLine(target.Fields["State"].Value);
Console.WriteLine(target.Fields["Type"].Value.ToString()); //Problem 3
With or without ToString() nothing really changes.
Any suggestions ?
EDIT: They are not null, I've checked while in Debug mode, they all have assigned values.
Use CoreField or builtin getters:
Console.WriteLine(target.Fields[CoreField.Title].Value);
Console.WriteLine(target.Fields[CoreField.AreaPath].Value);
Console.WriteLine(target.State);
Console.WriteLine(target.Type.Name);
This is going to top some of the weirdest things I've seen. I've tried looking up "simple t-sql delete causing timeout" but all titles are misleading, they say simple but are not. They deal with deleting millions of records or have complex relationships setup. I do not.
I have four tables:
tblInterchangeControl,
tblFunctionalGroup,
tblTransactionSet,
tblSegment
The latter 3 all associate to tblInterchangeConrol via InterchangeControlID. There are no relationships setup. like I said as simple as one could get.
The procedure runs a delete statement on all 4 tables like so...
DELETE FROM tblSegment
WHERE (ID_InterchangeControlID = #InterchangeControlID)
DELETE FROM tblTransactionSet
WHERE (ID_InterchangeControlID = #InterchangeControlID)
DELETE FROM tblFunctionalGroup
WHERE (ID_InterchangeControlID = #InterchangeControlID)
DELETE FROM tblInterchangeControl
WHERE (InterchangeControlID = #InterchangeControlID)
The weird part is if I leave these in the procedure it times out, if I remove them, it does not. I've pinned it to these delete statements that are the cause. But Why?!
I included c# because I'm calling this procedure from a c# application. I don't think this is the issue but maybe. I only say I don't think so because my code work just fine when I remove the delete statements inside the stored procedure. Then if I put them back, an exception is thrown that it's timed out.
In case my comment is the answer.
Most likely you have some locks holding those deletes up.
If you run a query from a command line SQL tool or from SQL Management Studio it will take whatever it needs to complete the query. So yes, most likely it's client part issue. And, because you mentioned c# it's probably ADO.NET command timeout.
Also, I'd suggest to profile the queries by inspecting their execution plans. In case you don't have indexes (primary/unique key constraints) this will result to full-scan, i.e. O(n) operation you don't want.
Update:
OK, looks like it's ADO.NET error. In your code, just prior executing the command increase the timeout:
var myCommand = new SqlCommand("EXEC ..."); // you create it something like this
....
myCommand.CommandTimeout = 300; // 5 minutes
myCommand.ExecuteNonReader(); // assuming your SP doesn't return anything
I have datareader which reads through 5 names with different values attached to each name.
While debugging i can get to each name using this expression computed by VS:
(new System.Collections.Generic<System.IO.FileInfo>(((School.PackageReader)(reader))._incomingStudents)).Items[0].Name
This above code while debugging gives me values i need like 5 different names when i change Items from 0 to 1 or 2... But when i try to use above code in my .cs file i get errors. Is there anyway to use this in code and get the values?
The error you are receiving is because you did not define the type of Collection you wanted to use.
I assume you are looking for a List, in which case you need to instantiate it this way:
(new System.Collections.Generic.List<System.IO.FileInfo>(((School.PackageReader)(reader))._incomingStudents)).Items[0].Name
Though it doesn't seem like this would be a good case for a List as you are calling a single value in Items[0].Name. BUT that's where your error is coming from.
i would like a clear answer of why can't i process a query like this one with OleDb
"select top 0 * FROM [APPELLATION$] WHERE (((([libel_app] LIKE '%g') OR ([region] LIKE '%g')) OR ([couleur] LIKE '%g')))"
I can with SQL but when i try to fetch some data from an Excel file it throws an error that tells me that i use some restricted word or i have some symbols that are restricted. I read the list of restricted words and symbols and did not find any of them in my query. My program is giving me SQL request, i would not like to end up looking if the TOP N number is whether or not is zero, but if i have no solution...
Thanks in advance.
Your collegues should remove hard-coded flavor-specific SQL from their code in the first place especially if it is to be used on different types of connections.
See the accepted answer on Is there an ANSI SQL alternative to the MYSQL LIMIT keyword? for some of the flavors. Excel is not listed there, I bet it uses the same syntax as MsAccess but I'm not suprised it acts completely different upon such a weird query. As Paddy already mentioned that query does not make any sense, and should be avoided.
Fixing this by matching "SELECT TOP 0" is ugly and will make maintaining software pure hell (been there :( )
The N in TOP N must be a numeric value of 1 (Banker's rounded) or greater.
e.g.
SELECT TOP 0.5 * FROM MyTable; -- rounds to zero = error
SELECT TOP 0.6 * FROM MyTable; -- rounds to 1 = no problem