Solved

ado dbf connection string doesnt accept spaces?

Posted on 2002-04-16
11
255 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

914 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

21 Experts available now in Live!

Get 1:1 Help Now