Solved

ado dbf connection string doesnt accept spaces?

Posted on 2002-04-16
11
258 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 70

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 70

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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

726 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