Showing posts with label finally. Show all posts
Showing posts with label finally. Show all posts

Thursday, March 29, 2012

Datatype conversion strangeness

Hi all,

After more headbanging and cursing than an entire Metallica audience, I have finally deduced how to store and calculate the values of a stack storing RPN calculations using a recursive stored procedure. But there is a new conundrum. Originally, to test the above, I was using fairly simple values -- 10, 20, +, 3, /, etc. But the real data is likely to include values with at least a couple of decimal places -- these have been configured using the money data type. Nevertheless, in my actual stack table the value needs to be specified as a varchar. However, as soon as I start sending in 0.68 as a varchar to my stored procedure, it gives an error.

Can anyone offer any light on this?

(The error message number is 245, data type conversion error. But this is inexplicable as I have commented out any conversion code in order to get to the root of the problem. As far as I am aware this value "0.68" is always being passed around as a varchar.)

Thanks.

But you might be doing some operation that involves say concatenation of numeric value with varchar or vice versa. This will result in implicit conversion of the value to the data type with highest precedence and depending on the value you can get run-time errors. It is hard to tell what is wrong without looking at some repro. You should however avoid doing these type of operations since the potential for misinterpretation or run-time error is large. If you are dealing with numeric values then specify the data type of the variables accordingly.|||Umachandar,

Many thanks for your reply. The reason I'm doing it this way is that I'm modelling a stack. Also some values are actually the tablename.objectname id of values in a read-only section of the database, so the <value> part of this stack has to be flexible -- hence varchar. Surely the potential for runtime error is not that great, as I only want to be able to handle values such as the following:-

table1.id1 (this gets parsed by the stored procedure into values such as follow...)
0.68
0.43
10
20
+
*

|||Again, it is hard to tell what is wrong without looking at some piece of code that reproes the error. Alternatively, you could run profiler trace with statement level events to see which statement is failing (you can even get this from the error message header which will point to the line that generated the error).|||OK let me try to explain as fully as possible.

I have a table NEO_FORMULA_STACK (f_id(int), position(int), val(varchar(100)), valname(varchar(100)), units (nvarchar(12).

I have a stored proc, which accepts f_id (as above) as a parameter. Based on this f_id it then loads the 'stack' of values into table TEMP_STACK (pos(int),val(varchar(100).

What I mean is that there are multiple formulas in the original table each with their own 'stack' of values (arranged in Reverse Polish Notation format, i.e. 10,20,+,3,/ [a way of writing ((10+20)/3).

Now, in the course of the load from NEO_FORMULA_STACK TO TEMP_STACK conversions such as tablename.objectname being evaluated to e.g. 0.098 might very well occur. But my impression is that if NEO_FORMULA_STACK has a val column of VARCHAR(100) datatype, and so does TEMP_STACK, then there should be absolutely no problem going from 'tablename.objectname' to '0.000918'. These are BOTH completely valid strings. Bear in mind that NO calculation has taken place at this point, I have simply loaded NEO_FORMULA_STACK for a particular f_id into TEMP_STACK. Attempting to pop off a value like '0.0098' into a temporary variable of varchar(100) is throwing error: 245, converting from varchar to int at line 77 of the stored proc:-

I can't give you the exact line, because one sp is calling another so the line it cites as being in the wrong is a comment.

Please let me know if you need more detail, or if you have any clues based on this information. Many thanks!
|||"But you might be doing some operation that involves say concatenation of numeric value with varchar or vice versa. This will result in implicit conversion of the value to the data type with highest precedence and depending on the value you can get run-time errors."

I assure you I am doing no concatenation or anything like that. I removed all such code in order to try and attack the problem. I am loading one varchar into another varchar, then popping that varchar off into a temporary variable of type varchar -- and it is that pop which is throwing the error, saying illegal conversion, when as far as I can see they are ALL varchar(100).
|||Your explanation doesn't really help to clarify the exact operations being done in the SP. As I said, this error happens due to implicit conversions of values of different types or initialization of variables/parameters using value of different data type. Add additional debug statements to see the results before the input so you can identify the issue. Or create a simpler repro that will help you identify the problem due to implicit conversion.

Sunday, March 25, 2012

DATASOUCE problem with SQL CLIENT from POCKET PC

I've been struggling to put together an install setup for an app on a pocket
pc. This app accesses a network SQL 2005 server.
I finally got things working - found some .CAB's that needed to be installed
on the PPC for SQL CE and SQL CLIENT.
But now I'm getting an odd error. In my SQL connection string I'm
specifying DATASOURCE=SPSERVER (which is the network server for SQL 2005 on
our domain). But instead it's connecting to a laptop SQL 2000 instance -
laptop name is FPS-LAP-SZ. I've googled for a bug like this and found no
info.
How do I guarantee the latest .CAB's for SQL CE and SQL CLIENT for my PPC
install?Hello Steve!
Correction: It's "Data Source=" or "Server=" not "DATASOURCE="
You may find the latest version of SQL Server CE from the following link:
http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=85e0c3ce-3fa1-453a-8ce9-af6ca20946c3
Ekrem Ã?nsoy
"Steve Z" <SteveZ@.discussions.microsoft.com> wrote in message
news:7508FAC3-F20E-4AB9-85AF-8E02782751D2@.microsoft.com...
> I've been struggling to put together an install setup for an app on a
> pocket
> pc. This app accesses a network SQL 2005 server.
> I finally got things working - found some .CAB's that needed to be
> installed
> on the PPC for SQL CE and SQL CLIENT.
> But now I'm getting an odd error. In my SQL connection string I'm
> specifying DATASOURCE=SPSERVER (which is the network server for SQL 2005
> on
> our domain). But instead it's connecting to a laptop SQL 2000 instance -
> laptop name is FPS-LAP-SZ. I've googled for a bug like this and found no
> info.
> How do I guarantee the latest .CAB's for SQL CE and SQL CLIENT for my PPC
> install?|||I have "DATA SOURCE=SPSERVER" - I typed it wrong in my post.
How about the latest download for SQL CLIENT for PPC?
"Ekrem Ã?nsoy" wrote:
> Hello Steve!
>
> Correction: It's "Data Source=" or "Server=" not "DATASOURCE="
> You may find the latest version of SQL Server CE from the following link:
> http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=85e0c3ce-3fa1-453a-8ce9-af6ca20946c3
>
> --
> Ekrem Ã?nsoy
>
> "Steve Z" <SteveZ@.discussions.microsoft.com> wrote in message
> news:7508FAC3-F20E-4AB9-85AF-8E02782751D2@.microsoft.com...
> > I've been struggling to put together an install setup for an app on a
> > pocket
> > pc. This app accesses a network SQL 2005 server.
> >
> > I finally got things working - found some .CAB's that needed to be
> > installed
> > on the PPC for SQL CE and SQL CLIENT.
> >
> > But now I'm getting an odd error. In my SQL connection string I'm
> > specifying DATASOURCE=SPSERVER (which is the network server for SQL 2005
> > on
> > our domain). But instead it's connecting to a laptop SQL 2000 instance -
> > laptop name is FPS-LAP-SZ. I've googled for a bug like this and found no
> > info.
> >
> > How do I guarantee the latest .CAB's for SQL CE and SQL CLIENT for my PPC
> > install?
>

Dataset.Clear() doesn't mark rows as deleted

Ok, I've spent a good amount on time on debugging an unupdating scenario in my application. Finally I knew the reason which is very annoying. Either I'm missing something really obvious (I hope so,) or this is a bug.

to reproduce what I'm talking about:
1- create a new win forms application using VS2005 sp1
2- add some SQL Compact Edition data file that have some records from the data menu, you'll get the designer to generate the dataset and everything..
3- drag a table from the data sources window, you'll get the data grid and the navigator on the form
4- add a button and have this in the click event handler:
datasetname.Clear();
TableAdapterName.Update(datasetname);

launch the program, click the button, you'll see the grid get wiped out as it supposed to do. close the program and relaunch. the data is there again (this has nothing to do with the copy always, copy if newer infamous stupidity)

now:
5- edit the click event handler and change it so something like this:
foreach (datasetname.TableRow row in datasetname.Table)
{
row.Delete();
}
TableAdapterName.Update(datasetname);

Launch the program, hit the button, grid wiped out. exit and relaunch. You'll see no data (i.e. the update on table adapter worked alright)

You can also try the GetChanges method on the dataset rightafter you use the clear method and you'd get no deleted records at all.

So, in 100,000+ records dataset, if i need to wipe the thing out and add some new records do i have to loop over every record and call delete (which will take LOTS of time).
I do hope that I'm missing something obvious.

Any help would be highly appreciated.

Thanks.

Yes, that's because Clear() is not supposed to mark rows as deleted, it suppose to clear tables of all row regardless of the row states.

Besides there’s no magic way to mark all rows as deleted except by looping through them, so should Clear() actually do that it would take a while anyway.

If you need to delete all the rows and then add some here’s how to do that efficiently:

1. Execute SQL query(ies) to delete rows strait from the database.

2. Create new empty DataSet with the same schema and use it instead of existing one (which would be collected).

3. Add rows you need.

4. Execute update using new DataSet.

Wednesday, March 21, 2012

dataset isn't showing

SQL/RS 2K, VS .Net 2003 - several single resultset/dataset reports working
just fine, finally got some multiple-resultset/dataset reports working very
well, too. today, however, i am creating a new one that isn't working, and i
can't yet determine why.
i have 5 different datasets so far, each are command type text, each field
presents the data just fine in the Data tab. I've created tables in the
Layout tab for each dataset, and dragged/dropped the fields into each
accordingly. When I go into the Preview tab, each dataset/table is visible
only intermittently' Meaning, I'm in Preview, and 3 of the five
datasets/tables are showing data, the other two are blank. Now, if i hit
refresh, only two are showing data... AND one of them is one that wasn't
showing data a moment ago.
I'm setting this thing up just like the three i did yesterday, which are
working just fine.
Can anybody provide any direction on this? It's very, very important, and I
do appreciate any assistance.
--
LynnWeird. I haven't seen this before. I suggest trying to deploy and see if
this is something only from the development environment.
Bruce Loehle-Conger
MVP SQL Server Reporting Services
"Lynn" <Lynn@.discussions.microsoft.com> wrote in message
news:278379C7-06BF-4726-B3DA-18EE50B6EAFA@.microsoft.com...
> SQL/RS 2K, VS .Net 2003 - several single resultset/dataset reports working
> just fine, finally got some multiple-resultset/dataset reports working
> very
> well, too. today, however, i am creating a new one that isn't working,
> and i
> can't yet determine why.
> i have 5 different datasets so far, each are command type text, each field
> presents the data just fine in the Data tab. I've created tables in the
> Layout tab for each dataset, and dragged/dropped the fields into each
> accordingly. When I go into the Preview tab, each dataset/table is
> visible
> only intermittently' Meaning, I'm in Preview, and 3 of the five
> datasets/tables are showing data, the other two are blank. Now, if i hit
> refresh, only two are showing data... AND one of them is one that wasn't
> showing data a moment ago.
> I'm setting this thing up just like the three i did yesterday, which are
> working just fine.
> Can anybody provide any direction on this? It's very, very important, and
> I
> do appreciate any assistance.
> --
> Lynn