473,320 Members | 2,112 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,320 software developers and data experts.

odbc create dsn for access using vb.net

SBK
I'm having trouble using VB.Net to create a system DSN.
I cannot use DSN-less connection, must use ODBC.
I have seen the "Creating odbc dsn with C#".
I have seen many VB examples for creating an dsn for access db, but they seem inconsistent: E.g: Do I use \0 or chr$(0) or chr(0) for the null between attributes? Do I need the null values in the string?
Here is what I have, and it just returns false (or 'zero').

'-----START------
Imports System.Runtime.InteropServices
Class ODBCDLL
Public Declare Auto Function SQLConfigDataSource Lib "ODBCCP32.DLL" _
(ByVal hwndParent As Long, ByVal fRequest As Long, _
ByVal lpszDriver As String, ByVal lpszAttributes As String) _
As Integer
End Class

Module CreateDSN

Private Const ODBC_ADD_SYS_DSN = 4 ' Add data source

Public Sub Main()

Dim dbpath as String = "C:\Program Files\AFolder\dbName.mdb"

Dim ret As Integer, Driver as String, Attributes as String

Driver = "Microsoft Access Driver (*.MDB)" & Chr(0)
Attributes = "DSN=" & "Hello" & Chr(0)
Attributes = Attributes & "Uid=Admin" & Chr(0) & "pwd=" & Chr(0)
Attributes = Attributes & "DBQ=" & dbpath & Chr(0) & Chr(0)

ret = ODBCDLL.SQLConfigDataSource(0&, ODBC_ADD_SYS_DSN, Driver, Attributes)
'ret is equal to 1 on success and 0 if there is an error
If ret <> 1 Then
MsgBox("DSN Creation Failed")
End If

End Sub 'Main

End Module
'-------------END--------------

On testing, this always returns 0 (into 'ret'). (It does the same thing when
using \0 instead of Chr(0). I'm not sure how to get any error messages.
Eg: I read we're supposed to use SQLInstallerError but have no idea how to
do that).
I'm not sure what else to try.
So, Any help would be appreciated (especially for VB.NET). Thank you...
Nov 20 '05 #1
1 11459
Hi SBK,

Without looking to the code a long in VBNet is a Int32 maybe you can try
that first mostly than all problems are resolved.

Cor
Nov 20 '05 #2

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

Similar topics

11
by: Wolfgang Kaml | last post by:
Hello All, I have been working on this for almost a week now and I haven't anything up my sleeves anymore that I could test in addition or change.... Since I am not sure, if this is a Windows...
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...
4
by: Roger Redford | last post by:
Dear Experts, I'm attempting to marry a system to an Oracle 817 datbase. Oracle is my specialty, the back end mainly, so I don't know much about java or javascript. The system uses javascript...
4
by: Jacob Pallapati | last post by:
Hi, I need to create an ODBC connection for one of my databases from the command line. I could use db2 catalog system odbc database source <my-database>. But I want to create a DSN with a name...
12
by: Remco Groot Beumer | last post by:
Hello all, Currently we are implementing an Access database which has to send some (not much) data over a WAN. We are using an Access front end and an Access back end. Basicly the front end runs...
2
by: Tina Robichaux | last post by:
I have found info on this problem at MS, but they say this problem does not occur with SQL 2K and MDAC 2.6 SP2, yet I am still experiencing it: I have a SQL user specifically created to SELECT...
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...
4
by: Phil Latio | last post by:
Scenario is: We have an intranet on which a Helpdesk application can be accessed. Data input into the Helpdesk is stored in a Access 2000 database, held on a server. This is great, works fine,...
0
by: Greg Corradini | last post by:
Hello, Lately I've been using the mx.ODBC module to query Access (mdb) tables. For the life of me, I can't get the 'create table' sql command to work. I use this command in Oracle and I've seen...
4
by: Jeff | last post by:
I need to export MySQL data to Access. As always, there seems to be more than one way to do this. I notice that PHP has: DB.php If I was doing this in perl, there would be an ODBC driver...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work

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.