473,394 Members | 1,870 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Relink (ODBC) tables and query's in Access via VB.NET

Hi,

I want to make a small application in VB.NET that relinks all the query's
and tables in an Access database that are linked via ODBC to an SQL Server.
It must be able to relink all the tables and query's to a given databse, on
a given sql server with given login and password.

Aybody knows how to do that, or better: has a sample application doing this?

Thanks in advance!

Pieter
Nov 20 '05 #1
11 4558
Cor
Hi Pieter,

I was writing something to ask you to be more precise, when I thougth maybe
is this what you are looking for.

http://www.connectionstrings.com/

http://www.able-consulting.com/ADO_Conn.htm

I not be something more precise please?

Cor

I want to make a small application in VB.NET that relinks all the query's
and tables in an Access database that are linked via ODBC to an SQL Server. It must be able to relink all the tables and query's to a given databse, on a given sql server with given login and password.

Aybody knows how to do that, or better: has a sample application doing this?

Nov 20 '05 #2
No, it's not that: what I need is something that refeshes the linked tables
and query's, not that connects to them. I have it in Access, but not in
VB.NET. (See underneath this). I'm just looking for a 'translation' of the
code below:

Option Compare Database
Option Explicit
'-- Global Connection Strings --
Global Const oudeDSN = "ODBC;DSN=OldOdbcName"
Private intLengte As Integer
Global Const iDSN = "OdbcName"
Global Const iSRVR = "ServerName"
Global Const iDATABASE = "DatabaseName"
Global Const iUID = "UserId"
Global Const iPWD = "Password"
Type TableDefinition
name As String
SourceTableName As String
End Type
Global arrTbl() As TableDefinition

Function RefreshAttach()
DoCmd.Hourglass True
'-----------------------------
'-- Function Refresh Attach --
'-----------------------------
On Error Resume Next
Dim ldb As Database
Dim tdf As TableDef
Dim qdf As QueryDef
Dim wrktdf As String
Dim wrksrc As String
Dim r As Integer
Dim s As Integer
Dim varReturn As Variant
' Return reference to current database.
Set ldb = CurrentDb
s = -1
Erase arrTbl

intLengte = Len(oudeDSN)

For r = 0 To ldb.TableDefs.Count - 1
' Keep Params
If (ldb.TableDefs(r).Attributes And dbAttachedODBC) And
(Left(ldb.TableDefs(r).Connect, intLengte) = oudeDSN) Then
s = s + 1
ReDim Preserve arrTbl(0 To s)
arrTbl(s).name = ldb.TableDefs(r).name
arrTbl(s).SourceTableName = ldb.TableDefs(r).SourceTableName
End If
Next r
For r = 0 To s
varReturn = SysCmd(acSysCmdSetStatus, "Attaching Table " &
arrTbl(r).name)
ldb.TableDefs.Delete arrTbl(r).name
ldb.TableDefs.Refresh
Set tdf = ldb.CreateTableDef(arrTbl(r).name, dbAttachSavePWD)
tdf.SourceTableName = arrTbl(r).SourceTableName
tdf.Connect = "ODBC;DSN=" & iDSN & ";SRVR=" & iSRVR & ";DATABASE=" &
iDATABASE & ";UID=" & iUID & ";PWD=" & iPWD & ";TABLE=" &
arrTbl(r).SourceTableName & ""
On Error Resume Next
ldb.TableDefs.Append tdf
On Error GoTo RefreshAttach_Err
ldb.TableDefs.Refresh
Set tdf = Nothing
Next r
Erase arrTbl
s = -1
For r = 0 To ldb.QueryDefs.Count - 1
' Keep Params
If (ldb.QueryDefs(r).Type = dbQSQLPassThrough) And
(Left(ldb.QueryDefs(r).Connect, intLengte) = oudeDSN) Then
s = s + 1
ReDim Preserve arrTbl(0 To s)
arrTbl(s).name = ldb.QueryDefs(r).name
End If
Next r

For r = 0 To s
varReturn = SysCmd(acSysCmdSetStatus, "Attaching Query " &
arrTbl(r).name)
Set qdf = ldb.QueryDefs(arrTbl(r).name)
qdf.Connect = "ODBC;DSN=" & iDSN & ";SRVR=" & iSRVR & ";DATABASE=" &
iDATABASE & ";UID=" & iUID & ";PWD=" & iPWD & ""
ldb.QueryDefs.Refresh
Set qdf = Nothing
Next r

Set ldb = Nothing

RefreshAttach_End:
varReturn = SysCmd(acSysCmdSetStatus, " ")
DoCmd.Hourglass False
Exit Function

RefreshAttach_Err:
' Display error information.
DoCmd.Hourglass False
MsgBox "Error number " & Err.Number & ": " & Err.Description
' Resume with statement following occurrence of error.
DoCmd.Hourglass True
Resume RefreshAttach_End:
End Function

Function AttachRemoveDbo() As Integer
On Error GoTo RemoveDbo_err
Dim CurrentDatabase As Database
Dim MyDocument As Document
Dim J As Integer
Set CurrentDatabase = DBEngine(0)(0)
For J = 0 To CurrentDatabase.Containers("Tables").Documents.Cou nt - 1
Set MyDocument = CurrentDatabase.Containers("Tables").Documents(J)
If Left(MyDocument.name, 4) = "dbo_" Then
DoCmd.Rename Mid(MyDocument.name, 5), A_TABLE, MyDocument.name
End If
Next J
AttachRemoveDbo = True
AttachRemoveDbo_exit:
Exit Function
AttachRemoveDbo_err:
MsgBox Error
AttachRemoveDbo = False
Resume AttachRemoveDbo_exit
End Function

"Cor" <no*@non.com> wrote in message
news:#5**************@TK2MSFTNGP09.phx.gbl...
Hi Pieter,

I was writing something to ask you to be more precise, when I thougth maybe is this what you are looking for.

http://www.connectionstrings.com/

http://www.able-consulting.com/ADO_Conn.htm

I not be something more precise please?

Cor

I want to make a small application in VB.NET that relinks all the query's and tables in an Access database that are linked via ODBC to an SQL

Server.
It must be able to relink all the tables and query's to a given databse,

on
a given sql server with given login and password.

Aybody knows how to do that, or better: has a sample application doing

this?


Nov 20 '05 #3
"DraguVaso" <pi**********@hotmail.com> schrieb
No, it's not that: what I need is something that refeshes the linked
tables and query's, not that connects to them. I have it in Access,
but not in VB.NET. (See underneath this). I'm just looking for a
'translation' of the code below:

I didn't find a ADO.NET solution, but one using ADOX:

http://support.microsoft.com/default...b;en-us;275249
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #4
On Tue, 9 Dec 2003 09:27:59 +0100, "DraguVaso" <pi**********@hotmail.com> wrote:

¤ No, it's not that: what I need is something that refeshes the linked tables
¤ and query's, not that connects to them. I have it in Access, but not in
¤ VB.NET. (See underneath this). I'm just looking for a 'translation' of the
¤ code below:
¤
¤ Option Compare Database
¤ Option Explicit
¤ '-- Global Connection Strings --
¤ Global Const oudeDSN = "ODBC;DSN=OldOdbcName"
¤ Private intLengte As Integer
¤ Global Const iDSN = "OdbcName"
¤ Global Const iSRVR = "ServerName"
¤ Global Const iDATABASE = "DatabaseName"
¤ Global Const iUID = "UserId"
¤ Global Const iPWD = "Password"
¤ Type TableDefinition
¤ name As String
¤ SourceTableName As String
¤ End Type
¤ Global arrTbl() As TableDefinition
¤
¤ Function RefreshAttach()
¤ DoCmd.Hourglass True
¤ '-----------------------------
¤ '-- Function Refresh Attach --
¤ '-----------------------------
¤ On Error Resume Next
¤ Dim ldb As Database
¤ Dim tdf As TableDef
¤ Dim qdf As QueryDef
¤ Dim wrktdf As String
¤ Dim wrksrc As String
¤ Dim r As Integer
¤ Dim s As Integer
¤ Dim varReturn As Variant
¤ ' Return reference to current database.
¤ Set ldb = CurrentDb
¤ s = -1
¤ Erase arrTbl
¤
¤ intLengte = Len(oudeDSN)
¤
¤ For r = 0 To ldb.TableDefs.Count - 1
¤ ' Keep Params
¤ If (ldb.TableDefs(r).Attributes And dbAttachedODBC) And
¤ (Left(ldb.TableDefs(r).Connect, intLengte) = oudeDSN) Then
¤ s = s + 1
¤ ReDim Preserve arrTbl(0 To s)
¤ arrTbl(s).name = ldb.TableDefs(r).name
¤ arrTbl(s).SourceTableName = ldb.TableDefs(r).SourceTableName
¤ End If
¤ Next r
¤ For r = 0 To s
¤ varReturn = SysCmd(acSysCmdSetStatus, "Attaching Table " &
¤ arrTbl(r).name)
¤ ldb.TableDefs.Delete arrTbl(r).name
¤ ldb.TableDefs.Refresh
¤ Set tdf = ldb.CreateTableDef(arrTbl(r).name, dbAttachSavePWD)
¤ tdf.SourceTableName = arrTbl(r).SourceTableName
¤ tdf.Connect = "ODBC;DSN=" & iDSN & ";SRVR=" & iSRVR & ";DATABASE=" &
¤ iDATABASE & ";UID=" & iUID & ";PWD=" & iPWD & ";TABLE=" &
¤ arrTbl(r).SourceTableName & ""
¤ On Error Resume Next
¤ ldb.TableDefs.Append tdf
¤ On Error GoTo RefreshAttach_Err
¤ ldb.TableDefs.Refresh
¤ Set tdf = Nothing
¤ Next r
¤ Erase arrTbl
¤ s = -1
¤ For r = 0 To ldb.QueryDefs.Count - 1
¤ ' Keep Params
¤ If (ldb.QueryDefs(r).Type = dbQSQLPassThrough) And
¤ (Left(ldb.QueryDefs(r).Connect, intLengte) = oudeDSN) Then
¤ s = s + 1
¤ ReDim Preserve arrTbl(0 To s)
¤ arrTbl(s).name = ldb.QueryDefs(r).name
¤ End If
¤ Next r
¤
¤ For r = 0 To s
¤ varReturn = SysCmd(acSysCmdSetStatus, "Attaching Query " &
¤ arrTbl(r).name)
¤ Set qdf = ldb.QueryDefs(arrTbl(r).name)
¤ qdf.Connect = "ODBC;DSN=" & iDSN & ";SRVR=" & iSRVR & ";DATABASE=" &
¤ iDATABASE & ";UID=" & iUID & ";PWD=" & iPWD & ""
¤ ldb.QueryDefs.Refresh
¤ Set qdf = Nothing
¤ Next r
¤
¤ Set ldb = Nothing
¤
¤ RefreshAttach_End:
¤ varReturn = SysCmd(acSysCmdSetStatus, " ")
¤ DoCmd.Hourglass False
¤ Exit Function
¤
¤ RefreshAttach_Err:
¤ ' Display error information.
¤ DoCmd.Hourglass False
¤ MsgBox "Error number " & Err.Number & ": " & Err.Description
¤ ' Resume with statement following occurrence of error.
¤ DoCmd.Hourglass True
¤ Resume RefreshAttach_End:
¤ End Function
¤
¤ Function AttachRemoveDbo() As Integer
¤ On Error GoTo RemoveDbo_err
¤ Dim CurrentDatabase As Database
¤ Dim MyDocument As Document
¤ Dim J As Integer
¤ Set CurrentDatabase = DBEngine(0)(0)
¤ For J = 0 To CurrentDatabase.Containers("Tables").Documents.Cou nt - 1
¤ Set MyDocument = CurrentDatabase.Containers("Tables").Documents(J)
¤ If Left(MyDocument.name, 4) = "dbo_" Then
¤ DoCmd.Rename Mid(MyDocument.name, 5), A_TABLE, MyDocument.name
¤ End If
¤ Next J
¤ AttachRemoveDbo = True
¤ AttachRemoveDbo_exit:
¤ Exit Function
¤ AttachRemoveDbo_err:
¤ MsgBox Error
¤ AttachRemoveDbo = False
¤ Resume AttachRemoveDbo_exit
¤ End Function
¤

You should be able to Refresh linked tables using ADOX (Microsoft ADO Ext 2.x for DDL and Security):

Sub RefreshLinkedTablesWithADOX()

Dim ADOXTable As New ADOX.Table
Dim ADOXCatalog As New ADOX.Catalog
Dim ADOConnection As New ADODB.Connection
Dim LinkProviderString As String
Dim LinkDataSource As String

Try

ADOConnection.Open("Provider=Microsoft.Jet.OLEDB.4 .0;" & _
"Data Source=e:\My Documents\db1.mdb;" & _
"Jet OLEDB:Engine Type=4;")

ADOXCatalog.ActiveConnection = ADOConnection

For Each ADOXTable In ADOXCatalog.Tables
If ADOXTable.Type = "LINK" Then
LinkProviderString = ADOXTable.Properties("Jet OLEDB:Link Provider
String").Value
LinkDataSource = ADOXTable.Properties("Jet OLEDB:Link Datasource").Value
ADOXTable.Properties("Jet OLEDB:Link Provider String").Value =
LinkProviderString
ADOXTable.Properties("Jet OLEDB:Link Datasource").Value = LinkDataSource
End If
Next
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
ADOConnection.Close()
End Try

End Sub
Paul ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)
Nov 20 '05 #5
That's what I was looking for! I'll try it tomorrow!
I guess it's allmost the same for refreshing query's?

Thanks a lot!

Pieter

"Paul Clement" <Us***********************@swspectrum.com> wrote in message
news:qb********************************@4ax.com...
On Tue, 9 Dec 2003 09:27:59 +0100, "DraguVaso" <pi**********@hotmail.com> wrote:
¤ No, it's not that: what I need is something that refeshes the linked tables ¤ and query's, not that connects to them. I have it in Access, but not in
¤ VB.NET. (See underneath this). I'm just looking for a 'translation' of the ¤ code below:
¤
¤ Option Compare Database
¤ Option Explicit
¤ '-- Global Connection Strings --
¤ Global Const oudeDSN = "ODBC;DSN=OldOdbcName"
¤ Private intLengte As Integer
¤ Global Const iDSN = "OdbcName"
¤ Global Const iSRVR = "ServerName"
¤ Global Const iDATABASE = "DatabaseName"
¤ Global Const iUID = "UserId"
¤ Global Const iPWD = "Password"
¤ Type TableDefinition
¤ name As String
¤ SourceTableName As String
¤ End Type
¤ Global arrTbl() As TableDefinition
¤
¤ Function RefreshAttach()
¤ DoCmd.Hourglass True
¤ '-----------------------------
¤ '-- Function Refresh Attach --
¤ '-----------------------------
¤ On Error Resume Next
¤ Dim ldb As Database
¤ Dim tdf As TableDef
¤ Dim qdf As QueryDef
¤ Dim wrktdf As String
¤ Dim wrksrc As String
¤ Dim r As Integer
¤ Dim s As Integer
¤ Dim varReturn As Variant
¤ ' Return reference to current database.
¤ Set ldb = CurrentDb
¤ s = -1
¤ Erase arrTbl
¤
¤ intLengte = Len(oudeDSN)
¤
¤ For r = 0 To ldb.TableDefs.Count - 1
¤ ' Keep Params
¤ If (ldb.TableDefs(r).Attributes And dbAttachedODBC) And
¤ (Left(ldb.TableDefs(r).Connect, intLengte) = oudeDSN) Then
¤ s = s + 1
¤ ReDim Preserve arrTbl(0 To s)
¤ arrTbl(s).name = ldb.TableDefs(r).name
¤ arrTbl(s).SourceTableName = ldb.TableDefs(r).SourceTableName
¤ End If
¤ Next r
¤ For r = 0 To s
¤ varReturn = SysCmd(acSysCmdSetStatus, "Attaching Table " &
¤ arrTbl(r).name)
¤ ldb.TableDefs.Delete arrTbl(r).name
¤ ldb.TableDefs.Refresh
¤ Set tdf = ldb.CreateTableDef(arrTbl(r).name, dbAttachSavePWD)
¤ tdf.SourceTableName = arrTbl(r).SourceTableName
¤ tdf.Connect = "ODBC;DSN=" & iDSN & ";SRVR=" & iSRVR & ";DATABASE=" & ¤ iDATABASE & ";UID=" & iUID & ";PWD=" & iPWD & ";TABLE=" &
¤ arrTbl(r).SourceTableName & ""
¤ On Error Resume Next
¤ ldb.TableDefs.Append tdf
¤ On Error GoTo RefreshAttach_Err
¤ ldb.TableDefs.Refresh
¤ Set tdf = Nothing
¤ Next r
¤ Erase arrTbl
¤ s = -1
¤ For r = 0 To ldb.QueryDefs.Count - 1
¤ ' Keep Params
¤ If (ldb.QueryDefs(r).Type = dbQSQLPassThrough) And
¤ (Left(ldb.QueryDefs(r).Connect, intLengte) = oudeDSN) Then
¤ s = s + 1
¤ ReDim Preserve arrTbl(0 To s)
¤ arrTbl(s).name = ldb.QueryDefs(r).name
¤ End If
¤ Next r
¤
¤ For r = 0 To s
¤ varReturn = SysCmd(acSysCmdSetStatus, "Attaching Query " &
¤ arrTbl(r).name)
¤ Set qdf = ldb.QueryDefs(arrTbl(r).name)
¤ qdf.Connect = "ODBC;DSN=" & iDSN & ";SRVR=" & iSRVR & ";DATABASE=" & ¤ iDATABASE & ";UID=" & iUID & ";PWD=" & iPWD & ""
¤ ldb.QueryDefs.Refresh
¤ Set qdf = Nothing
¤ Next r
¤
¤ Set ldb = Nothing
¤
¤ RefreshAttach_End:
¤ varReturn = SysCmd(acSysCmdSetStatus, " ")
¤ DoCmd.Hourglass False
¤ Exit Function
¤
¤ RefreshAttach_Err:
¤ ' Display error information.
¤ DoCmd.Hourglass False
¤ MsgBox "Error number " & Err.Number & ": " & Err.Description
¤ ' Resume with statement following occurrence of error.
¤ DoCmd.Hourglass True
¤ Resume RefreshAttach_End:
¤ End Function
¤
¤ Function AttachRemoveDbo() As Integer
¤ On Error GoTo RemoveDbo_err
¤ Dim CurrentDatabase As Database
¤ Dim MyDocument As Document
¤ Dim J As Integer
¤ Set CurrentDatabase = DBEngine(0)(0)
¤ For J = 0 To CurrentDatabase.Containers("Tables").Documents.Cou nt - 1 ¤ Set MyDocument = CurrentDatabase.Containers("Tables").Documents(J) ¤ If Left(MyDocument.name, 4) = "dbo_" Then
¤ DoCmd.Rename Mid(MyDocument.name, 5), A_TABLE, MyDocument.name
¤ End If
¤ Next J
¤ AttachRemoveDbo = True
¤ AttachRemoveDbo_exit:
¤ Exit Function
¤ AttachRemoveDbo_err:
¤ MsgBox Error
¤ AttachRemoveDbo = False
¤ Resume AttachRemoveDbo_exit
¤ End Function
¤

You should be able to Refresh linked tables using ADOX (Microsoft ADO Ext 2.x for DDL and Security):
Sub RefreshLinkedTablesWithADOX()

Dim ADOXTable As New ADOX.Table
Dim ADOXCatalog As New ADOX.Catalog
Dim ADOConnection As New ADODB.Connection
Dim LinkProviderString As String
Dim LinkDataSource As String

Try

ADOConnection.Open("Provider=Microsoft.Jet.OLEDB.4 .0;" & _
"Data Source=e:\My Documents\db1.mdb;" & _
"Jet OLEDB:Engine Type=4;")

ADOXCatalog.ActiveConnection = ADOConnection

For Each ADOXTable In ADOXCatalog.Tables
If ADOXTable.Type = "LINK" Then
LinkProviderString = ADOXTable.Properties("Jet OLEDB:Link Provider String").Value
LinkDataSource = ADOXTable.Properties("Jet OLEDB:Link Datasource").Value ADOXTable.Properties("Jet OLEDB:Link Provider String").Value = LinkProviderString
ADOXTable.Properties("Jet OLEDB:Link Datasource").Value = LinkDataSource End If
Next
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
ADOConnection.Close()
End Try

End Sub
Paul ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)

Nov 20 '05 #6
On Tue, 09 Dec 2003 17:52:41 GMT, "DraguVaso" <pi**********@hotmail.com> wrote:

¤ That's what I was looking for! I'll try it tomorrow!
¤ I guess it's allmost the same for refreshing query's?
¤

Can't say I've tried it with QueryDefs, but in ADOX they are defined in the Procedures collection.
Paul ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)
Nov 20 '05 #7
I'm becoming mad of it!

I just don't find it for the query's!

I tried allmost everything with the Procedures colelction, and I jsut don't
find how to do it :-(

I'm now trying with DAO and Querydef, but there I just don't manage to do a
"database = new dao.database". weird and frustrating!!!

"Paul Clement" <Us***********************@swspectrum.com> wrote in message
news:7j********************************@4ax.com...
On Tue, 09 Dec 2003 17:52:41 GMT, "DraguVaso" <pi**********@hotmail.com> wrote:
¤ That's what I was looking for! I'll try it tomorrow!
¤ I guess it's allmost the same for refreshing query's?
¤

Can't say I've tried it with QueryDefs, but in ADOX they are defined in the Procedures collection.

Paul ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)

Nov 20 '05 #8
On Wed, 10 Dec 2003 16:30:00 +0100, "DraguVaso" <pi**********@hotmail.com> wrote:

¤ I'm becoming mad of it!
¤
¤ I just don't find it for the query's!
¤
¤ I tried allmost everything with the Procedures colelction, and I jsut don't
¤ find how to do it :-(
¤
¤ I'm now trying with DAO and Querydef, but there I just don't manage to do a
¤ "database = new dao.database". weird and frustrating!!!

You may want to try the following. This is about the only method I can think of that might cause a
Refresh:

Sub RefreshAccessQueryDefs()

Dim ADOXTable As New ADOX.Table
Dim ADOXCatalog As New ADOX.Catalog
Dim ADOXProc As ADOX.Procedure
Dim ADOConnection As New ADODB.Connection
Dim ProcedureName As String

Try
ADOConnection.Open("Provider=Microsoft.Jet.OLEDB.4 .0;" & _
"Data Source=e:\My Documents\db1.mdb;" & _
"Jet OLEDB:Engine Type=4;")

ADOXCatalog.ActiveConnection = ADOConnection

Dim ADOCommand As ADODB.Command
For Each ADOXProc In ADOXCatalog.Procedures
ProcedureName = ADOXProc.Name
ADOCommand = New ADODB.Command
ADOCommand = ADOXCatalog.Procedures(ProcedureName).Command
ADOCommand.CommandText = ADOXCatalog.Procedures(ProcedureName).Command.Comm andText
ADOXCatalog.Procedures(ProcedureName).Command = ADOCommand
Next ADOXProc
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
ADOConnection.Close()
End Try

End Sub
Paul ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)
Nov 20 '05 #9
Thanks!
Actually: this code (and the code for the tables) works most of the times.
BUT (aaargh, why this 'but', hehe):
In some case it gives me an error, and it's always with the same
Access-database I got eveytime that error: With these Access-database it
'thinks' there aren't any Tables or Procedures in it. So the statements in
the For-loop "For Each ADOXProc In ADOXCatalog.Procedures" aren't done att
all!

When I looked more closely to it it gace me an exception:
"System.Runtime.InteropServices.COMException (0x80010105): The server threw
an exception."

I runned the folowwing code:
Dim ADOConnection As New ADODB.Connection
Dim cat As New ADOX.Catalog
Dim tbl As New ADOX.Table
Dim prc As ADOX.Procedure
Dim strProcName As String
Dim cmd As ADODB.Command
SyncLock (GetType(clsDB))
Try
ADOConnection.Open("Provider=Microsoft.Jet.OLEDB.4 .0;Data
Source=" & strDirFile)
cat.ActiveConnection = ADOConnection

Try
MessageBox.Show(cat.Tables.Count)

-> On the cat.Tables.Count I got the error.
More info about the error:

?ex.tostring
"System.Runtime.InteropServices.COMException (0x80010105): The server threw
an exception.
at ADOX.Tables.get_Count()
at RefreshODBC.clsDB.subRefresh() in C:\VB NET\RefreshODBC\clsDB.vb:line
29"

?ex.gettype
{System.RuntimeType}
[System.RuntimeType]: {System.RuntimeType}
Assembly: {System.Reflection.Assembly}
AssemblyQualifiedName: "System.Runtime.InteropServices.COMException,
mscorlib, Version=1.0.5000.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089"
Attributes: 1056769
BaseType: {System.RuntimeType}
DeclaringType: Nothing
DefaultBinder: {System.DefaultBinder}
Delimiter: "."c
EmptyTypes: {Length=0}
FilterAttribute: {System.Reflection.MemberFilter}
FilterName: {System.Reflection.MemberFilter}
FilterNameIgnoreCase: {System.Reflection.MemberFilter}
FullName: "System.Runtime.InteropServices.COMException"
GUID: {System.Guid}
HasElementType: False
IsAbstract: False
IsAnsiClass: True
IsArray: False
IsAutoClass: False
IsAutoLayout: True
IsByRef: False
IsClass: True
IsCOMObject: False
IsContextful: False
IsEnum: False
IsExplicitLayout: False
IsImport: False
IsInterface: False
IsLayoutSequential: False
IsMarshalByRef: False
IsNestedAssembly: False
IsNestedFamANDAssem: False
IsNestedFamily: False
IsNestedFamORAssem: False
IsNestedPrivate: False
IsNestedPublic: False
IsNotPublic: False
IsPointer: False
IsPrimitive: False
IsPublic: True
IsSealed: False
IsSerializable: True
IsSpecialName: False
IsUnicodeClass: False
IsValueType: False
MemberType: TypeInfo
Missing: {System.Reflection.Missing}
Module: {System.Reflection.Module}
Name: "COMException"
Namespace: "System.Runtime.InteropServices"
ReflectedType: Nothing
TypeHandle: {System.RuntimeTypeHandle}
TypeInitializer: Nothing
UnderlyingSystemType: {System.RuntimeType}

?ex.hresult
-2147417851

Anybody had any idea?

Thanks! :-)

"Paul Clement" <Us***********************@swspectrum.com> wrote in message
news:34********************************@4ax.com...
On Wed, 10 Dec 2003 16:30:00 +0100, "DraguVaso" <pi**********@hotmail.com> wrote:
¤ I'm becoming mad of it!
¤
¤ I just don't find it for the query's!
¤
¤ I tried allmost everything with the Procedures colelction, and I jsut don't ¤ find how to do it :-(
¤
¤ I'm now trying with DAO and Querydef, but there I just don't manage to do a ¤ "database = new dao.database". weird and frustrating!!!

You may want to try the following. This is about the only method I can think of that might cause a Refresh:

Sub RefreshAccessQueryDefs()

Dim ADOXTable As New ADOX.Table
Dim ADOXCatalog As New ADOX.Catalog
Dim ADOXProc As ADOX.Procedure
Dim ADOConnection As New ADODB.Connection
Dim ProcedureName As String

Try
ADOConnection.Open("Provider=Microsoft.Jet.OLEDB.4 .0;" & _
"Data Source=e:\My Documents\db1.mdb;" & _
"Jet OLEDB:Engine Type=4;")

ADOXCatalog.ActiveConnection = ADOConnection

Dim ADOCommand As ADODB.Command
For Each ADOXProc In ADOXCatalog.Procedures
ProcedureName = ADOXProc.Name
ADOCommand = New ADODB.Command
ADOCommand = ADOXCatalog.Procedures(ProcedureName).Command
ADOCommand.CommandText = ADOXCatalog.Procedures(ProcedureName).Command.Comm andText ADOXCatalog.Procedures(ProcedureName).Command = ADOCommand
Next ADOXProc
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
ADOConnection.Close()
End Try

End Sub
Paul ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)

Nov 20 '05 #10
On Fri, 12 Dec 2003 13:46:55 +0100, "DraguVaso" <pi**********@hotmail.com> wrote:

¤ Thanks!
¤ Actually: this code (and the code for the tables) works most of the times.
¤ BUT (aaargh, why this 'but', hehe):
¤ In some case it gives me an error, and it's always with the same
¤ Access-database I got eveytime that error: With these Access-database it
¤ 'thinks' there aren't any Tables or Procedures in it. So the statements in
¤ the For-loop "For Each ADOXProc In ADOXCatalog.Procedures" aren't done att
¤ all!
¤
¤ When I looked more closely to it it gace me an exception:
¤ "System.Runtime.InteropServices.COMException (0x80010105): The server threw
¤ an exception."
¤
¤ I runned the folowwing code:
¤ Dim ADOConnection As New ADODB.Connection
¤ Dim cat As New ADOX.Catalog
¤ Dim tbl As New ADOX.Table
¤ Dim prc As ADOX.Procedure
¤ Dim strProcName As String
¤ Dim cmd As ADODB.Command
¤ SyncLock (GetType(clsDB))
¤ Try
¤ ADOConnection.Open("Provider=Microsoft.Jet.OLEDB.4 .0;Data
¤ Source=" & strDirFile)
¤ cat.ActiveConnection = ADOConnection
¤
¤ Try
¤ MessageBox.Show(cat.Tables.Count)
¤
¤ -> On the cat.Tables.Count I got the error.
¤ More info about the error:
¤
¤ ?ex.tostring
¤ "System.Runtime.InteropServices.COMException (0x80010105): The server threw
¤ an exception.
¤ at ADOX.Tables.get_Count()
¤ at RefreshODBC.clsDB.subRefresh() in C:\VB NET\RefreshODBC\clsDB.vb:line
¤ 29"
¤
¤ ?ex.gettype
¤ {System.RuntimeType}
¤ [System.RuntimeType]: {System.RuntimeType}
¤ Assembly: {System.Reflection.Assembly}
¤ AssemblyQualifiedName: "System.Runtime.InteropServices.COMException,
¤ mscorlib, Version=1.0.5000.0, Culture=neutral,
¤ PublicKeyToken=b77a5c561934e089"
¤ Attributes: 1056769
¤ BaseType: {System.RuntimeType}
¤ DeclaringType: Nothing
¤ DefaultBinder: {System.DefaultBinder}
¤ Delimiter: "."c
¤ EmptyTypes: {Length=0}
¤ FilterAttribute: {System.Reflection.MemberFilter}
¤ FilterName: {System.Reflection.MemberFilter}
¤ FilterNameIgnoreCase: {System.Reflection.MemberFilter}
¤ FullName: "System.Runtime.InteropServices.COMException"
¤ GUID: {System.Guid}
¤ HasElementType: False
¤ IsAbstract: False
¤ IsAnsiClass: True
¤ IsArray: False
¤ IsAutoClass: False
¤ IsAutoLayout: True
¤ IsByRef: False
¤ IsClass: True
¤ IsCOMObject: False
¤ IsContextful: False
¤ IsEnum: False
¤ IsExplicitLayout: False
¤ IsImport: False
¤ IsInterface: False
¤ IsLayoutSequential: False
¤ IsMarshalByRef: False
¤ IsNestedAssembly: False
¤ IsNestedFamANDAssem: False
¤ IsNestedFamily: False
¤ IsNestedFamORAssem: False
¤ IsNestedPrivate: False
¤ IsNestedPublic: False
¤ IsNotPublic: False
¤ IsPointer: False
¤ IsPrimitive: False
¤ IsPublic: True
¤ IsSealed: False
¤ IsSerializable: True
¤ IsSpecialName: False
¤ IsUnicodeClass: False
¤ IsValueType: False
¤ MemberType: TypeInfo
¤ Missing: {System.Reflection.Missing}
¤ Module: {System.Reflection.Module}
¤ Name: "COMException"
¤ Namespace: "System.Runtime.InteropServices"
¤ ReflectedType: Nothing
¤ TypeHandle: {System.RuntimeTypeHandle}
¤ TypeInitializer: Nothing
¤ UnderlyingSystemType: {System.RuntimeType}
¤
¤ ?ex.hresult
¤ -2147417851
¤
¤ Anybody had any idea?
¤

Have you tried compacting the database or running a repair. I can't think of any other reason why it
would work on your other databases but not this one.
Paul ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)
Nov 20 '05 #11
On Fri, 12 Dec 2003 13:46:55 +0100, "DraguVaso" <pi**********@hotmail.com> wrote:

¤ Thanks!
¤ Actually: this code (and the code for the tables) works most of the times.
¤ BUT (aaargh, why this 'but', hehe):
¤ In some case it gives me an error, and it's always with the same
¤ Access-database I got eveytime that error: With these Access-database it
¤ 'thinks' there aren't any Tables or Procedures in it. So the statements in
¤ the For-loop "For Each ADOXProc In ADOXCatalog.Procedures" aren't done att
¤ all!
¤
¤ When I looked more closely to it it gace me an exception:
¤ "System.Runtime.InteropServices.COMException (0x80010105): The server threw
¤ an exception."
¤
¤ I runned the folowwing code:
¤ Dim ADOConnection As New ADODB.Connection
¤ Dim cat As New ADOX.Catalog
¤ Dim tbl As New ADOX.Table
¤ Dim prc As ADOX.Procedure
¤ Dim strProcName As String
¤ Dim cmd As ADODB.Command
¤ SyncLock (GetType(clsDB))
¤ Try
¤ ADOConnection.Open("Provider=Microsoft.Jet.OLEDB.4 .0;Data
¤ Source=" & strDirFile)
¤ cat.ActiveConnection = ADOConnection
¤
¤ Try
¤ MessageBox.Show(cat.Tables.Count)
¤
¤ -> On the cat.Tables.Count I got the error.
¤ More info about the error:
¤
¤ ?ex.tostring
¤ "System.Runtime.InteropServices.COMException (0x80010105): The server threw
¤ an exception.
¤ at ADOX.Tables.get_Count()
¤ at RefreshODBC.clsDB.subRefresh() in C:\VB NET\RefreshODBC\clsDB.vb:line
¤ 29"
¤
¤ ?ex.gettype
¤ {System.RuntimeType}
¤ [System.RuntimeType]: {System.RuntimeType}
¤ Assembly: {System.Reflection.Assembly}
¤ AssemblyQualifiedName: "System.Runtime.InteropServices.COMException,
¤ mscorlib, Version=1.0.5000.0, Culture=neutral,
¤ PublicKeyToken=b77a5c561934e089"
¤ Attributes: 1056769
¤ BaseType: {System.RuntimeType}
¤ DeclaringType: Nothing
¤ DefaultBinder: {System.DefaultBinder}
¤ Delimiter: "."c
¤ EmptyTypes: {Length=0}
¤ FilterAttribute: {System.Reflection.MemberFilter}
¤ FilterName: {System.Reflection.MemberFilter}
¤ FilterNameIgnoreCase: {System.Reflection.MemberFilter}
¤ FullName: "System.Runtime.InteropServices.COMException"
¤ GUID: {System.Guid}
¤ HasElementType: False
¤ IsAbstract: False
¤ IsAnsiClass: True
¤ IsArray: False
¤ IsAutoClass: False
¤ IsAutoLayout: True
¤ IsByRef: False
¤ IsClass: True
¤ IsCOMObject: False
¤ IsContextful: False
¤ IsEnum: False
¤ IsExplicitLayout: False
¤ IsImport: False
¤ IsInterface: False
¤ IsLayoutSequential: False
¤ IsMarshalByRef: False
¤ IsNestedAssembly: False
¤ IsNestedFamANDAssem: False
¤ IsNestedFamily: False
¤ IsNestedFamORAssem: False
¤ IsNestedPrivate: False
¤ IsNestedPublic: False
¤ IsNotPublic: False
¤ IsPointer: False
¤ IsPrimitive: False
¤ IsPublic: True
¤ IsSealed: False
¤ IsSerializable: True
¤ IsSpecialName: False
¤ IsUnicodeClass: False
¤ IsValueType: False
¤ MemberType: TypeInfo
¤ Missing: {System.Reflection.Missing}
¤ Module: {System.Reflection.Module}
¤ Name: "COMException"
¤ Namespace: "System.Runtime.InteropServices"
¤ ReflectedType: Nothing
¤ TypeHandle: {System.RuntimeTypeHandle}
¤ TypeInitializer: Nothing
¤ UnderlyingSystemType: {System.RuntimeType}
¤
¤ ?ex.hresult
¤ -2147417851
¤
¤ Anybody had any idea?
¤

Have you tried compacting the database or running a repair. I can't think of any other reason why it
would work on your other databases but not this one.
Paul ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)
Nov 20 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Andreas Lauffer | last post by:
I changed from Access97 to AccessXP and I have immense performance problems. Details: - Access XP MDB with Jet 4.0 ( no ADP-Project ) - Linked Tables to SQL-Server 2000 over ODBC I used...
11
by: DJJ | last post by:
I am using the MySQL ODBC 3.51 driver to link three relatively small MySQL tables to a Microsoft Access 2003 database. I am finding that the data from the MySQL tables takes a hell of a long time...
3
by: Random Person | last post by:
Does anyone know how to use VBA to relink tables between two MS Access databases? We have two databases, one with VBA code and the other with data tables. The tables are referenced by linked...
3
by: Ian | last post by:
We are currently experiencing problems with our Access XP database. We are using access as the front-end and are connecting to Oracle 7.3 via ODBC. Our users are running Win 98 and Win Xp. We are...
2
by: PeteCresswell | last post by:
My code for DoCmd.TransferDatabase stopped working after applying the update in question. Seems like the last argument (optional: SaveLogInID) can no longer be specified when...
7
by: Joe | last post by:
I am using Access 2003 and are linking to an Oracle 9i ODBC datasource (using Oracle ODBC drivers). After linking the tables in Access, I inspect the data contained in the linked tables. For...
0
by: DraguVaso | last post by:
Hi, I need to relink a whole bunch of Access-Linked-Tables and Pass-Through-Query's to another ODBC with VB.NET I foudn alreaddy how to relink the Tables, and I thought the query's woudl be...
4
by: Oceania | last post by:
Hi All, I did try using the sample code from the ADO.net forum to link one table, it is working fine. But, I got a problem when I tried to link all tables (20 tables)... Please help, thank...
8
by: Greg Strong | last post by:
Hello All, The short questions are 1 Do you know how to make DSN connection close in Access to Oracle 10g Express Edition? &/or 2 Do you know how to make a DSN-less pass-through query...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.