Solved

SQL Server xp

Posted on 2001-08-01
16
212 Views
Last Modified: 2010-04-02
I'm tring to write an xp for SQL Server 7.

When I build it in debug mode it returns one set of records and when I build it in release mode it brings back a different set of records.

I'm not a C++ programmer so I have no idea of what might be causing this problem.

Any help would be gratefully accepted.

Cheers.

Matt.
0
Comment
Question by:UncleMatt
  • 9
  • 7
16 Comments
 
LVL 2

Author Comment

by:UncleMatt
ID: 6340048
I forgot to mention I am writing it in Visual C++

Oops!
0
 
LVL 4

Expert Comment

by:IainHere
ID: 6341199
What is the difference between the records?  Are they from the same table? database?

Are there any other obvious differences between the debug and release versions?  Does the software work fine apart from this?

Which set of records (if either) is the correct one?  ie which set were you expecting to see?
0
 
LVL 4

Expert Comment

by:IainHere
ID: 6341252
>I'm not a C++ programmer so I have no idea of what might be causing this problem.

What kind of advice are you expecting?
0
 
LVL 2

Author Comment

by:UncleMatt
ID: 6341685
Iain,

I'm returning 1 row to SQL Server, when in Debug it returns correctly, when in Release it doesn't only returns 2 of the fields and null in the others.

I was stupidly hoping for it to be an obvious setting problem or something, give me a break, I haven't touched C in 2 years and never to this depth.

Matt.
0
 
LVL 4

Expert Comment

by:IainHere
ID: 6343869
Are you writing the data to the database or reading from the database when the problem occurs?  Is it repeatable, or does it work the first time and fail subsequently? If reading from, are you sure that you're not simply reading a different row (I know, a stupid mistake, but I've made stupider in the past).

How many fields are there, and of what type are they - for instance, can you read[/write] int but fail to read string?  If you know where the problem is occurring in the code, could you post a few lines - I think it's unlikely to be a setting problem.

Apologies for above comment, and break given.
0
 
LVL 2

Author Comment

by:UncleMatt
ID: 6344131
In the xp I'm accessing data from an API call to a 3rd party DLL and sending it to the SQL Server as a row of 6 strings.  

It's a postcode lookup system.  

In debug mode it returns all the rows correctly, but in release mode, with the same arguments it only returns 2 of the 6 fields correctly.  

I'm in contact with the company that supplied the postcode DLL aswell to see if they can help, but I'm confused by the different results for different versions.

Matt.

PS Apology accepted, and thanks for the break, first one this week!!
0
 
LVL 4

Expert Comment

by:IainHere
ID: 6344185
Do you have debug and release versions of the DLL, or are you using a release version for both versions of your XP?

The first thing I would do would be to write the strings to a file (or a messagebox) just before you return them to the database.  At least then you'll know roughly where the problem is.  I've done lots of database work, but never actually written an XP - if its something specific to how they work, then it'll be beyond me.  From how it sounds, I would *guess* that it's to do with initializing the variables though, which is done for you in the debug mode, but if you haven't looked after your memory properly, this is the kind of thing you could hit.  Could you post some code?

Oh, and maybe a link to this in the MSSQL TA would bring someone with more knowledge of XP.
0
 
LVL 2

Author Comment

by:UncleMatt
ID: 6345422
I don't think it's the xp specific code because the strings are empty anyway.  I'll check out the variable initialisation in the morning and if I don't have any luck I'll post my code.

Matt.
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 2

Author Comment

by:UncleMatt
ID: 6348025
I think I've found my problem.  The postcode lookup uses a structure of char arrays and when it is returned with the information, they aren't null terminated.  Some of the fields are getting lost in my moving them from the struct to the output.

I've definately proven that its not the xp specific stuff then, but I've got to think of a way to get the information out I need.

Any suggestions would be great, as I mentioned before C++ is not my area.

Matt.
0
 
LVL 2

Author Comment

by:UncleMatt
ID: 6348154
Right, I think I've fixed it.  

I accessed to structure in the order of it's definition and it almost worked, I needed to do something with one of the variables first, before sending it back to SQL Server before SQL Server could see it, so I just put it in the column twice (That sounds like a typical VB problem).  

It works now.

Thanks for the help Iain, I'll give you the points when I get home (work internet access is not so good.)
0
 
LVL 4

Expert Comment

by:IainHere
ID: 6349301
I've just thought - are you Uncle Travelling Matt :-)

I don't really understand what your last comment means, about putting it in the column twice, but it sounds like it might be a hack?  Then again, since you say it sounds like a typical VB problem, you probably know what you're doing.  C-style strings (char arrays) cause so many problems; Are you fully happy with your solution, or would you like a hand?
0
 
LVL 2

Author Comment

by:UncleMatt
ID: 6349328
I've just written another xp this afternoon and I had no problems at all after I accessed the data in the defined order, so I'm going to have a look at the original one tomorrow (Yes I have to get up on Saturday morning (again)) and see if I can fix that one without the hack I used (yes VB does need some bodging every now and then).

The string handling is coming back to me after 2 years of not touching C, but any advice on strings and structs of strings would be useful.

Why the question about Uncle Travelling Matt, you sound as if you think you know who I am?  I used to be nick-named UTM but the travelling got dropped when I stopped driving for a living!

Matt.
0
 
LVL 4

Accepted Solution

by:
IainHere earned 150 total points
ID: 6355029
I just remember watching Fraggle Rock as a kid, and all those postcards from UTM.  

Anyway, unless you fixed your problem over the weekend: if you're passing a struct in to the dll and some of the members are char*, then it would be very bad practice on the part of the library provider not to return the length of the string as well as the string itself (and doubly so if it's not bothering to terminate the string) - could you post the struct, and the signature of the function?  Perhaps also the code you're using to read from dll and write to DB - if there's not too much of it.
0
 
LVL 2

Author Comment

by:UncleMatt
ID: 6356295
Our work internet has been down all day so I can't post any code but the 2 I have written since the one I have had the problem with have worked without any trouble, I haven't had a chance to play with the original one again yet as it's been a little hectic today.

I'll try and post some code tomorrow.

Matt.
0
 
LVL 2

Author Comment

by:UncleMatt
ID: 6803668
sorry, have been in hospital for a number of months, trying to catch up now.

Thanks for your help all that time ago.

Matt.
0
 
LVL 4

Expert Comment

by:IainHere
ID: 6807165
Oh dear, hope you're better now, and thanks for the points  :-)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

762 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now