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?
Computer101Connect With a Mentor Commented:
PAQed with points refunded (50)

EE Admin
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.

A proven path to a career in data science

At Springboard, we know how to get you a job in data science. With Springboard’s Data Science Career Track, you’ll master data science  with a curriculum built by industry experts. You’ll work on real projects, and get 1-on-1 mentorship from a data scientist.

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.

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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.