|
-
Jul 14th, 2003, 12:10 PM
#1
Thread Starter
New Member
System.TyepInitialization.Exception on declaring ado.net connection
Posted - 07/14/2003 : 11:59:01 AM
--------------------------------------------------------------------------------
I've written a small app that worked fine on my laptop. The laptop is running windows 2000 with the .net framwork and development environment installed. I moved the exe and pdb generated by the build to one of our servers. This server has the .net framework on it. For some reason when I run it on this server I get the following error:
An exception 'System.TyepInitialization.Exception' has occurred in Myprogram.exe
The app did a number of things but, for the sake of debugging this problem, I've stripped eveything else out. All I have now is a public sub main with nothing in it and a global declartion at the top of the module:
Dim myConnection As New System.Data.OleDb.OleDbConnection()
That's all. If this declaration in there it causes the error. If it is commented out, the program runs (though it doesn't do anything).
We have other exe's running on this same server that also declare a New System.Data.OleDb.OleDbConnection() and they work fine. I added the adodb reference but the problem is still there. Any suggestions?
Thanks,
Neil
-
Jul 14th, 2003, 12:53 PM
#2
here's an example i made that may help you :
VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strPath As String = Application.StartupPath & "\db4.mdb"
Dim strPass As String = "sysop"
Dim Connection As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strPath & ";Jet OLEDB:Database Password=" & strPass & ";User ID=Admin;Persist Security Info=True" '/// in this case it's password protected.
Dim Command As String = "SELECT * FROM Table1"
OpenAccessFile(Connection, Command)
End Sub
Private Sub OpenAccessFile(ByVal strConnection As String, ByVal strCommand As String)
Try
Dim objDbConnection As New OleDbConnection(strConnection)
objDbConnection.Open() '///open a new connection.
Dim objCommand As New OleDbCommand(strCommand, objDbConnection)
Dim objAdaptor As OleDbDataAdapter
objAdaptor = New OleDbDataAdapter(objCommand)
Dim objDataSet As New DataSet()
objAdaptor.Fill(objDataSet, "Table1")
DataGrid1.DataSource = objDataSet.Tables("Table1") '///fill a datagrid with the recordset
objDbConnection.Close()
objCommand.Dispose()
objAdaptor.Dispose()
objDataSet.Dispose()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
hope it helps.
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
-
Jul 15th, 2003, 08:57 AM
#3
Thread Starter
New Member
I guess I should clarify. This program ran fine on another machine; it's our intranet server that is the problem. So this isn't a code problem
What I did was strip out all the code to see what line is causing the problem on our intranet server. As it turns out the line of code that causes the error is the declaration of the connection; that is the onlly line in the program that I left and I should be able to declare a variable and not use it without causing an error.
From what I've seen on the message boards, this is most probably an issue of hte object not being instantiated correctly. I'm not sure why this might be happening.
Thanks,
Neil
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|