Hi everyone:
I made a program in vb.net that calls a data base in MS ACCESS. it is propose to used in my company but first I compiled the code to work with my computer a 32 bits wit autocad 64 bits. my co workers have autocad 64 bits, so I changed the dlls to work with the 64 version, the dll is loaded and when I use some comand that calls the library it sendme the ekeynotfound error. but only in the 64 version.
here is my code. the variable names are in spanish because I'm from Costa Rica
the program do the next things:
-a class that when created it receives a string.
-create a conection with the DB.
-select some properties from the DB that match the string received.
but is not working in the 64 version.
Imports System.Data.OleDb Imports System.IO Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.DatabaseServices ''' <summary> ''' Clase cuya finalidad es abrir una conexion con la base de datos y obtener las propiedades de los bloques ''' </summary> ''' <remarks></remarks> Public Class PropiedadesBloque Public ReadOnly nombre As String #Region "propiedades de toma" Public ReadOnly esToma As Boolean = False Public ReadOnly esTomaSuperficie As Boolean = False Public ReadOnly esTomaPiso As Boolean = False Public ReadOnly esTomaGeneral As Boolean = False Public ReadOnly esTomaUPS As Boolean = False Public ReadOnly esTomaExterior As Boolean = False #End Region Public ReadOnly esSalidaEsp As Boolean = False Public ReadOnly esMotor As Boolean = False Public ReadOnly esSalidaDatSen As Boolean = False Public ReadOnly layer As String Public ReadOnly atributo As String Public ReadOnly descripcion As String Public ReadOnly contenido As String Public ReadOnly red As String ''' <summary> ''' Crea un objeto el cual posee las propiedades obtenidas a travez de la base de datos. ''' </summary> ''' <param name="nombreBloque">Nombre del bloque por el cual se buscaran las propiedades</param> ''' <remarks>Debe existir la base de datos dada por la constante FileName</remarks> Public Sub New(nombreBloque As String) nombre = nombreBloque Dim doc As Document = Application.DocumentManager.MdiActiveDocument Dim db As Database = doc.Database Try Dim cadenaConexion As String = "Provider=Microsoft.ACE.OLEDB.12.0;" & "Data Source=" & Path.GetDirectoryName(db.OriginalFileName) & "\Descripciones.accdb" 'se crean los elementos de la conexion Dim cnn As New OleDbConnection(cadenaConexion) Dim cmd As OleDbCommand = cnn.CreateCommand() cnn.Open() '------------consultas de toma---------- cmd.CommandText = "SELECT [Es toma] FROM Descripciones WHERE Simbolo = '" & nombre & "'" esToma = cmd.ExecuteScalar() If esToma Then cmd.CommandText = "SELECT [Es toma superficie] FROM Descripciones WHERE Simbolo = '" & nombre & "'" esTomaSuperficie = cmd.ExecuteScalar() cmd.CommandText = "SELECT [Es toma piso] FROM Descripciones WHERE Simbolo = '" & nombre & "'" esTomaPiso = cmd.ExecuteScalar() cmd.CommandText = "SELECT [Es toma general] FROM Descripciones WHERE Simbolo = '" & nombre & "'" esTomaGeneral = cmd.ExecuteScalar() cmd.CommandText = "SELECT [Es toma UPS] FROM Descripciones WHERE Simbolo = '" & nombre & "'" esTomaUPS = cmd.ExecuteScalar() cmd.CommandText = "SELECT [Es toma exterior] FROM Descripciones WHERE Simbolo = '" & nombre & "'" esTomaExterior = cmd.ExecuteScalar() End If '----------Consultas de salidas especiales cmd.CommandText = "SELECT [Es salida especial] FROM Descripciones WHERE Simbolo = '" & nombre & "'" esSalidaEsp = cmd.ExecuteScalar() cmd.CommandText = "SELECT [Es motor] FROM Descripciones WHERE Simbolo = '" & nombre & "'" esMotor = cmd.ExecuteScalar() cmd.CommandText = "SELECT [Es salida datos sencilla] FROM Descripciones WHERE Simbolo = '" & nombre & "'" esSalidaDatSen = cmd.ExecuteScalar() 'se agrega la propiedad del layer cmd.CommandText = "SELECT [Layer] FROM Descripciones WHERE Simbolo = '" & nombre & "'" layer = Convert.ToString(cmd.ExecuteScalar()) 'se agrega la propiedad del atributo cmd.CommandText = "SELECT [Atributo] FROM Descripciones WHERE Simbolo = '" & nombre & "'" atributo = Convert.ToString(cmd.ExecuteScalar()) 'se agrega la descripciĆ³n cmd.CommandText = "SELECT [Descripcion] FROM Descripciones WHERE Simbolo = '" & nombre & "'" descripcion = Convert.ToString(cmd.ExecuteScalar()) 'se agrega el contenido cmd.CommandText = "SELECT [Contenido del bloque] FROM Descripciones WHERE Simbolo = '" & nombre & "'" contenido = Convert.ToString(cmd.ExecuteScalar()) 'se agrega la red a la que pertenece cmd.CommandText = "SELECT [Red] FROM Descripciones WHERE Simbolo = '" & nombre & "'" red = Convert.ToString(cmd.ExecuteScalar()) 'se cierra la conexion cnn.Close() Catch ex As Exception End Try End Sub End Class
thanks all of you for your help.
"with my computer a 32 bits wit autocad 64 bits"? How can you use 64-bit AutoCAD with your 32-bit computer? I guess you probbaly meant that your computer is 32 bit with 32-bit AutoCAD, while your coworker uses 64-bit AutoCAD (thus, the computer OS is 64-bit, of course).
If your .NET project is set to target "Any CPU" (you should usually), not specific to x96 or x64, then the problem is likely not the DLL compiled from your project. You need to make sure the correct (32 or 64 bit) MS Access Engine installed.
The computer does not need to have MS Access installed, but must install MS Access Engine (free download), With 64 bit coomputer/64-bit AutoCAD, you need to install MS Access Engine for 64 bit, while if it is 32-bit AutoCAD, the computer need to have 32-MS Access Engine installed.
If the computer has MS Access installed, the the MS Access Engine is installed already (32 or 64bit, depending on MS Access version). However, in the same computer, you cannot have both 32 and 64 bit MS Access Engine (this is tru at least up to MS Office/Access 2010, but I am not sure for the latest).
Another option is to switch to mssql. SQL Express is free. This is what I had to do since our IT dept won't install the 64bit version of Office.
If you're going to go the SQL Server route instead of Access then you're probably better of with Compact. See http://blogs.msdn.com/b/jerrynixon/archive/2012/02/26/sql-express-v-localdb-v-sql-compact-edition.as... for the differences.
For Visual Studio this: https://visualstudiogallery.msdn.microsoft.com/0e313dfd-be80-4afb-b5e9-6e74d369f7a1 will make your life much easier