System.Runtime.InteropServices.COM

paramanj
paramanj used Ask the Experts™
on
I have this error when I run this code

An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in GetOrders.exe

Additional information: Invalid object name 'StaffAccountsDB'.


code:
________________________________________________________
Dim PT_dsCn As String
        Dim PT_dsStr As String
        Dim PT_intX As Integer
        Dim PT_X As Integer
        Dim PT_membersRs As ADODB.Recordset
        Dim PT_cn As New ADODB.Connection()


 PT_cn.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=nax;Initial _ Catalog=Development;Data Source= " & "myserver1" & ";Password=abcd"
        PT_cn.Open()
        PT_membersRs = New ADODB.Recordset()

        Try

        PT_membersRs.Open("Select * FROM StaffAccountsDB", PT_cn, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockBatchOptimistic)

        'Catch
            MsgBox(Err.Number & " " & Err.Description)
________________________________________________________
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2012
Top Expert 2008
Commented:
This might mean that you have two databases, and are accessing the wrong one, which is missing the StaffAccountsDB table.

Author

Commented:
Thanks for the answer, but I have the right database and table name.  It has to be somting else.
Most Valuable Expert 2012
Top Expert 2008
Commented:
First a question:  Why use ADO vs. ADO.NET?

Then a suggestion:  Try using ADOX, setup a Catalog, and examine the Tables property to see if the table exists.

Is this a Windows form project in VB.NET?  Does the user have access to the tables?

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial