Solved

String Problems

Posted on 2004-10-15
12
193 Views
Last Modified: 2010-04-23
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
0
Comment
Question by:tdyck12345
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
12 Comments
 
LVL 2

Author Comment

by:tdyck12345
ID: 12321433
Just to clarify, my sql command is a string and not an oledbcommand.

ie.

Dim sqlCommand as string = "Select * from tbCustomers;"
0
 
LVL 27

Expert Comment

by:planocz
ID: 12321615
Have you tried this...

Dim sqlCommand as string = "Select * from tbCustomers"
0
 
LVL 2

Author Comment

by:tdyck12345
ID: 12321726
No I have not tried that. Do you think the semi-colon is the problem?

0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
LVL 8

Expert Comment

by:bramsquad
ID: 12321942
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

0
 
LVL 2

Author Comment

by:tdyck12345
ID: 12322291
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
0
 
LVL 18

Expert Comment

by:DotNetLover_Baan
ID: 12322577
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
0
 
LVL 2

Author Comment

by:tdyck12345
ID: 12322718
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
0
 
LVL 2

Author Comment

by:tdyck12345
ID: 12323235
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
0
 
LVL 2

Author Comment

by:tdyck12345
ID: 12323541
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
0
 
LVL 2

Author Comment

by:tdyck12345
ID: 12427023
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
0
 

Accepted Solution

by:
PashaMod earned 0 total points
ID: 12464623
Closed, 500 points refunded.
PashaMod
Community Support Moderator
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

622 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question