Link to home
Start Free TrialLog in
Avatar of tdyck12345
tdyck12345

asked on

String Problems

I have a windows service that runs queries on a database using OleDb. I prepare a sql command and then execute the command. Every so often, the program will start cutting off the sql commands. A command such as "Select * from tbCustomers;" might get cut off to "Select * from tbCust". The sql execution fails and all subsequent attempts to run any sql commands also fail. The program then needs to be shut down and restarted.

So I switched to using System.Text.StringBuilder, but the same problems occurs.

Any ideas as to why this may be occurring? Any help would be greatly appreciated.

Troy
Avatar of tdyck12345
tdyck12345

ASKER

Just to clarify, my sql command is a string and not an oledbcommand.

ie.

Dim sqlCommand as string = "Select * from tbCustomers;"
Avatar of Howard Cantrell
Have you tried this...

Dim sqlCommand as string = "Select * from tbCustomers"
No I have not tried that. Do you think the semi-colon is the problem?

i doubt the semicolon is the reason the string is concatinating.

this problem is very strange.

i would step through your program, keep your eye on that variable and check to see when it concatinates.  another thing to check for, is it always a certain number of characters?  there might be a missed Mid() call or something along those lines.

~b

When the error occurs an exception is thrown. I catch the exception and at that point I am able to step through the code. I can see what is being assigned, but what the actual value of the string is concatenated. It is just a simple string assignment like this:

Dim sqlCommand as string = "Select * from tbCustomers;"

or

Dim sqlCommand as string = "Select * from tbCustomers where Cust_ID=" & Customer_ID & ";"

Troy
This is really strange. Never heard of it. I doubt there is somethingelse causing it. Are you changing the SQL query somewhere ? Are you generating it dynamically, depending on some conditions ?
-Baan
I am not changing the sql anywhere. The sql string is generated dynamically in that the variables passed to it change. But what I am doing is really quite a simple string assignment.

Is there anything i could be doing wrong elsewhere in the program with threads or something that would cause the program to behave unpredictably? Could it have to do with MTAThread vs STAThread?

Troy
After posting that last comment I found this site

http://sourceforge.net/mailarchive/forum.php?forum_id=29502&max_rows=25&style=nested&viewmonth=200312

and in it they claim that in their case there was a problem with using STAThreads over MTAThreads. I have some code that handles COM Port communications and it's apartment state was set to STAThread. While the rest of the program was set to MTA. I am going to make everything MTA, test it out and see what happens. I will let you know how it goes.

If anybody has any thoughts in the meantime, please let me know.

Troy
My changes did not help.

Another thing that might help is that this problem is much more likely to occur while I am in the debugger.

Troy
The problem turned out to be that I had a MS Access Database compiled into my application as an embedded resource. This was causing memory corruption and causing my application to perform unpredictably.

I have removed the resource and now everything works fine.

Troy
ASKER CERTIFIED SOLUTION
Avatar of PashaMod
PashaMod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial