Solved

ado dbf connection string doesnt accept spaces?

Posted on 2002-04-16
11
253 Views
Last Modified: 2007-11-27
i m using this connection string but
when the user select sourcedb = some path where
there are spaces in between the directory eg
"c:\thework\i   know\test.dbf"  i will get an error!
how to resolve this error?

oConn.Open "Driver={Microsoft Visual FoxPro Driver};" & _
                   "SourceType=DBF;" & _
                   "SourceDb=\somepath\mySourceDb.dbf;" & _
                   "Exclusive=No;"
0
Comment
Question by:spiral
  • 5
  • 4
  • 2
11 Comments
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 6945658
Have you tried:

oConn.Open "Driver={Microsoft Visual FoxPro Driver};" & _
                  "SourceType=DBF;" & _
                  "SourceDb=""\somepath\mySourceDb.dbf;""" & _
                  "Exclusive=No;"
0
 

Author Comment

by:spiral
ID: 6946485
yes i have tried but not working
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 6946499
is it possible that you cannot specify the dbf file into the connection string (you will name it into the query)?

see http://www.able-consulting.com/ADO_Conn.htm#ODBCDriverForVisualFoxPro
0
 
LVL 43

Accepted Solution

by:
TimCottee earned 50 total points
ID: 6947100
You can use the dbf file in the connection string if you ensure that you use adCmdTable in the recordset.Open statement. You could always use the shortpath form of the path:

Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal lBuffer As Long) As Long
Public Function GetShortPath(ByVal FileName As String) As String
    Dim lngRes As Long, strPath As String
    strPath = String$(165, 0)
    lngRes = GetShortPathName(FileName, strPath, 164)
    GetShortPath = Left$(strPath, lngRes)
End Function

....

oConn.Open  "Driver={Microsoft Visual FoxPro Driver};" & _
                 "SourceType=DBF;" & _
                 "SourceDb=" & GetShortPathName(""c:\thework\i   know\") & "test.dbf;" & _
                 "Exclusive=No;"
0
 

Author Comment

by:spiral
ID: 6947536
what does GetShortPathName do?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 43

Expert Comment

by:TimCottee
ID: 6947580
It returns the 8.3 path name that represents the path you are using for example:

c:\Program Files\Microsoft Visual Studio\VB98

becomes

c:\Progra~1\Micros~1\VB98

Which never includes spaces and should be understandable in win9x,NT,2000,XP
0
 

Author Comment

by:spiral
ID: 6948350
ok thanks i will try it out tomorrow
0
 

Author Comment

by:spiral
ID: 6949388
TimCottee: it works thank u. but when i try to rename my folder which has spaces to other filename directory, it doesnt allow me. how to release the kernel32.dll which was
accessing it previously?
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 6949852
spiral, can you explain that? You don't need to rename your folder to the 8.3 version as these are equivalent and refer to the SAME folder just in different ways. Wherever you use the fullpath you can use the shortpath in the same place.
0
 

Author Comment

by:spiral
ID: 6950138
i meant when i run my program under the vb6 development environment, everything is ok but when i unload my program
go to windows explorer and rename the folder which i previously accessed, i cant rename it. I need to shut down vb6 and then i can rename the file folder. why is this so?

it says the file folder is still in use. but i already unload my program! is the kernel32 causing this problem?
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 6950156
Kernel32 has nothing to do with this. My guess is that you have not properly terminated the ADO objects that you have instantiated. Ensure that you do oConn.Close and oRst.Close and then Set oConn = Nothing and Set oRst = Nothing when you have finished using the objects.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now