SQL DMO Attach Database

When I attach database using SQL DMO attach database method, following error message appears

Error Number : 5105
Error Message : [Microsoft][ODBC SQL Server Driver][SQL Server]Device activation error. The physical file name ''e:\Data' may be incorrect.

My data resides in following folder :
e:\data base\year 2008\current firm data\data0809.mdf
FileName1 = "e:\data base\year 2008\current firm data\data0809.mdf"
Filename2 = "e:\data base\year 2008\current firm data\data0809.ldf"
DBName = "data0809"
Set oSvroot = CreateObject("SQLDMO.SQLServer")
On Error GoTo AttachError
'Set the time out fairly high.
'Note this value is in seconds.
oSvroot.LoginTimeout = 60
oSvroot.Connect "(local)", "sa", ""
Call oSvroot.AttachDB(DBName, FileName1 & ", " & Filename2)

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Aneesh RetnakaranDatabase AdministratorCommented:
try after changing the paths like this


sankalpmehtaAuthor Commented:
how can i convert from  path like
"e:\data base\year 2008\current firm data\data0809.mdf"
to  path shown by you as

using coding techniques. I do not want to change it manually.

Aneesh RetnakaranDatabase AdministratorCommented:
the above one is the DOS naming format (8.3 format :-  8 characters for name + 3 for extension )
and the easiest way to get this path is

1. open the folder "C:\data base\year 2008\current firm data "  (make sure that this is the active window  )
2. Start ->run -> Command   ( it should be  command  and not 'cmd' )
3. type dir

you can see the dos path.

10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

sankalpmehtaAuthor Commented:
i understood but i want it using vb code and not manually.
Aneesh RetnakaranDatabase AdministratorCommented:
not sure
Check the System.Management / System.Diagnostics workspace. There possibly you will get something to find the DOS path.

Else cut at the 7th character and add "~1" is the dirty way.
sankalpmehtaAuthor Commented:
thanks all

I got the solution.

we can get the the short file path directly by using filesystemobject's shortpath command.

So i wish to close this question without assigning points to anybody..............................

Can you please post the solution / code here for others reference.
sankalpmehtaAuthor Commented:
yes offcourse.
here is the code.

Dim fso As FileSystemObject
Dim f
Dim sFileNameMDF As String

Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile(MDF_FileName)

MDF_ShortFilePath = UCase(f.Name)
MDF_ShortFilePath = f.ShortPath

Set f = Nothing
Set fso = Nothing
PAQed with points refunded (50)

EE Admin

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.