Results 1 to 3 of 3

Thread: System.TyepInitialization.Exception on declaring ado.net connection

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2003
    Posts
    6

    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

  2. #2
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    here's an example i made that may help you :
    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         Dim strPath As String = Application.StartupPath & "\db4.mdb"
    3.         Dim strPass As String = "sysop"
    4.  
    5.         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.
    6.         Dim Command As String = "SELECT * FROM Table1"
    7.         OpenAccessFile(Connection, Command)
    8.  
    9.     End Sub
    10.  
    11.     Private Sub OpenAccessFile(ByVal strConnection As String, ByVal strCommand As String)
    12.         Try
    13.             Dim objDbConnection As New OleDbConnection(strConnection)
    14.  
    15.             objDbConnection.Open() '///open a new connection.
    16.  
    17.             Dim objCommand As New OleDbCommand(strCommand, objDbConnection)
    18.             Dim objAdaptor As OleDbDataAdapter
    19.             objAdaptor = New OleDbDataAdapter(objCommand)
    20.             Dim objDataSet As New DataSet()
    21.             objAdaptor.Fill(objDataSet, "Table1")
    22.             DataGrid1.DataSource = objDataSet.Tables("Table1") '///fill a datagrid with the recordset
    23.  
    24.             objDbConnection.Close()
    25.             objCommand.Dispose()
    26.             objAdaptor.Dispose()
    27.             objDataSet.Dispose()
    28.         Catch ex As Exception
    29.             MsgBox(ex.Message)
    30.         End Try
    31.     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]

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2003
    Posts
    6
    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
  •  



Click Here to Expand Forum to Full Width