|
Hi, I am using VS.Net 2002 edition with the 1.1 framework both at University and at home (my home copy is from University using the University licence so I presume is exactly the same)
I have created a front-end application for SQLite (an open source DBMS) which creates databases for users with no SQL knowledge. I link to the DBMS using a .dll file.
When I fill a dataset with the contents of a table at University it works fine then goes onto fill a datagrid with this information. Yet when I run the same application at home I get a "Specified cast is not valid" error.
Not one thing changes to the application, the data in the table, the .dll file, everything is the same in the two instances yet one works and the other doesn't.
Does anyone know what is wrong, if I need to change a setting or install an update on my home PC or something?
Any help is greatly appreciated.
I have included my code and highlighted where the error shows up although I do not believe my code to be the problem as like I said it works on the University PC's.
Many thanks
John
Code for populating dataset and datagrid
Private Sub cmbInsertData_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbInsertData.SelectedIndexChanged<br />
Dim dset As DataSet '= New DataSet()<br />
If Len(cmbInsertData.SelectedItem) < 1 Then<br />
MessageBox.Show("Please choose a table to view")<br />
Else<br />
Try<br />
tblName = (cmbInsertData.Text)<br />
setTableName(tblName)<br />
dbConn.openExistingDatabse("Data Source=" & getDBName() & ";Version=3;New=False;Compress=True;")<br />
dbConn.createSQLCommand()<br />
Try<br />
dset = dbConn.selectAll("SELECT * FROM " & tblName, tblName)<br />
Catch es As Exception<br />
MessageBox.Show("error here -" & es.Message)<br />
End Try<br />
StoreDataSet.setDataSet(dset)<br />
DataGrid1.DataSource = dset.Tables(0).DefaultView<br />
Catch es As Exception<br />
MessageBox.Show(es.Message)<br />
End Try<br />
End If<br />
End Sub
Public Function selectAll(ByVal strSQL As String, ByVal tableName As String)<br />
Dim dset As DataSet = New DataSet()<br />
sqlite_cmd.CommandText = (strSQL)<br />
sqlite_datareader = sqlite_cmd.ExecuteReader()<br />
<br />
Dim sqlite_dataAdapter As SQLiteDataAdapter = New SQLiteDataAdapter(strSQL, sqlite_conn)<br />
sqlite_commandBuilder = New SQLiteCommandBuilder(sqlite_dataAdapter)<br />
sqlite_dataAdapter.Fill(dset, tableName)<br />
Return dset<br />
End Function
|
|
|
|
|
What you need to find out is what is getting casted? What is it? What is it being cast to?
At the moment you catch the exception and throw away all the good information.
|
|
|
|
|
Hi Colin, I am not really sure what you mean, how do I get all the other good information? I have been taught this way at University so as not to crash out the program.
What I find odd is that it can work on one machine and not the other.
|
|
|
|
|
Do you have a missing reference?
The machine at Uni may have a DLL that is not present on your machine or you may need to set up the reference again if it is a different location or version.
Steve
|
|
|
|
|
Hi Steve, I have tried re-referencing all the references which are present, this does not fix the error. Is there anyway I could find out what DLL could be missing or should I just leave it and be thankful it works at University?
John
|
|
|
|
|
You should be notified in the Task List if your project detects a missing reference.
What line of code is causing the error?
It is not highlited as you stated in your original post.
Steve
|
|
|
|
|
I get the impression that his code is compiling. The message he mentions suggests that he has got the code running. A missing referrence would mean the code wouldn't compile. Of course, he could be running the binaries he compiled at uni'.
|
|
|
|
|
Yes. I agree. Just a thought...
Steve
|
|
|
|
|
No I am not notified of a missing reference, sorry, I did highlight the line but then when I put the code in code tags it must have got rid of the bold, the line that causes the error is this one :-
dset = dbConn.selectAll("SELECT * FROM " & tblName, tblName)
John
|
|
|
|
|
What is 'dbConn'?
I'm confused how selectAll is a method of dbConn...
Steve
|
|
|
|
|
dbConnection is a class I created with all functions in that deal with the database.
In the forms I want to connect to the database I put this line of code:-
Dim dbConn As dbConnection = New dbConnection()
selectAll is a function I created to select all from the given table name, put the contents into a dataSet and display in a DataGrid.
|
|
|
|
|
What is the definition of this 'selectAll' method?
Steve
|
|
|
|
|
This is the selectAll code, I just called it selectAll(select *) as that is what I am doing from the database, selecting all from a table and displaying it to the user.
Public Function selectAll(ByVal strSQL As String, ByVal tableName As String)<br />
Dim dset As DataSet = New DataSet()<br />
sqlite_cmd.CommandText = (strSQL)<br />
sqlite_datareader = sqlite_cmd.ExecuteReader()<br />
<br />
Dim sqlite_dataAdapter As SQLiteDataAdapter = New SQLiteDataAdapter(strSQL, sqlite_conn)<br />
sqlite_commandBuilder = New SQLiteCommandBuilder(sqlite_dataAdapter)<br />
sqlite_dataAdapter.Fill(dset, tableName)<br />
Return dset<br />
End Function
|
|
|
|
|
Are those sqlite_*** items custom components or your own classes?
There is no expected line:
Dim sqlite_commandBuilder As SQLiteCommandBuilder
What are the 'CommandText' and 'ExecuteReader' lines doing?
Nothing as far as I can see...
Steve
|
|
|
|
|
Hi Steve, the sqlite_*** are my names I've given to them. Like in the code above, I've simply added the _ so when I come to use it elsewhere I know what it is, so SQLiteCommandBuilder becomes sqilte_commandBuilder. It's just easier for me. They come from a 3rd party wrapper which is finisar.sqlite which can be found at http://adodotnetsqlite.sourceforge.net/
the expected line of "Dim sqlite_commandBuilder As SQLiteCommandBuilder" is present and has been declared at the top of the dbConnection class with all the other things that need declaring.
Now that you mention it I don't know what those two lines are doing, they are there from when I started this project a long time ago and as it was working I never took anything out.
I've took them out and they makeno difference to the error messge so it looks as if they were not needed at all.
-- modified at 12:47 Saturday 5th August, 2006
|
|
|
|
|
Well, I'm at a loss my friend!
The only other thing I can see is the line:
Dim dset As DataSet
is repeated in 'cmbInsertData_SelectedIndexChanged' and in your 'selectAll' function. Don't know if that would cause an error...
I suspect it has something to do with one of your third party components. Maybe one of them is corrupted or something.
Good luck!
Steve
|
|
|
|
|
It's very weird as you would suspect it to either work on both my home and Uni PC's or neither, not to work on one and not the other.
Anyway thanks for your help and suggestions, they were very much appreciated.
Thanks again
John
|
|
|
|
|
Yes. This really suggests it is something other than your code.
Steve
|
|
|
|
|
I think I should be just glad it works at University and leave it at that.
Thanks again for your time and help, much appreciated.
John
|
|
|
|
|
newbjohny wrote: I have been taught this way at University so as not to crash out the program.
Your try/catch blocks here are being used for debugging purposes not to prevent the application from crashing. Using try/catch for debugging is a waste of time when there are better tools available.
Did your university not teach you how to set breakpoints and step through code and how to watch variables?
You need to find out the full stack trace of where the exception was thrown. By catching the exception and displaying only the message you've thrown all that information away - get rid of the try/catch and see where the application actaully crashes. When it does the Visual Studio debugger will show you exactly where the crash is (even if it is in code you did not write)
If you are missing a referrence your application is unlikely to compile on your home machine.
|
|
|
|
|
Hi, sadly they did not teach us to do anything other that the try and catch, to be honest they never really taught us, all the lecture notes were ripped straight from the recommended text book. Anyway thats a aside issue.
I've taken out the try-catch and it still crashes out with the same error, but two lines of code are highlighted, the one mentioned earlier in the form :-
dset = dbConn.selectAll("SELECT * FROM " & tblName, tblName)
and one in selectAll function in the connection class:-
sqlite_dataAdapter.Fill(dset, tableName)
A third line is highlighted in dissassembly but I have no idea what this is :-
00000014 mov ecx,eax
|
|
|
|
|
Ignore the disassembly - what is in the call stack? It should be in the lower half of the Visual Studio window. (Use the following to show it if it is not displayed: Debug-->Windows-->Call Stack)
newbjohny wrote: dset = dbConn.selectAll("SELECT * FROM " & tblName, tblName)
What is dbConn? I would assume it is a connection, but selectAll is (1) Not a standard method on a connection class and (2) does not conform to the .NET naming guidelines so it may have been written by someone with a Java background.
|
|
|
|
|
The previous two messages I wrote were from the Call stack.
dbConnection is a class I created with all functions in that deal with the database.
In the forms I want to connect to the database I put this line of code:-
Dim dbConn As dbConnection = New dbConnection()
selectAll is a function I created to select all from the given table name, put the contents into a dataSet and display in a DataGrid.
|
|
|
|
|
newbjohny wrote: Private Sub cmbInsertData_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbInsertData.SelectedIndexChanged
newbjohny wrote: Public Function selectAll(ByVal strSQL As String, ByVal tableName As String)
Are these two methods on the same class?
-- modified at 12:04 Saturday 5th August, 2006
What are the fields (aka member variables) on the class(es)?
|
|
|
|
|
No, the function is in a dbConnection class and the cmbinsertdata is on a form.
I'm sorry but I do not know what a member variable is.
Is there someway I could zip my code and email it to you, it may be easier if you could see the code.
John
|
|
|
|