Hey everyone!

I'm trying to use SQLDMO to programmatically attach a database. I
have a problem when the file name includes a space character, for
example: @"C:\Program Files\Microsoft SQL
Server\MSSQL\Data\DM_0814_ABCTrucking.mdf"

Here's a sample of code:

string tmp = @"C:\Program Files\Microsoft SQL
Server\MSSQL\Data\DM_0814_ABCTrucking.mdf" +"," +@"C:\Program
Files\Microsoft SQL Server\MSSQL\Data\DM_0814_ABCTrucking_log.ldf";

SQLDMO.SQLServer sqlDMOConn = new SQLDMO.SQLServer();

sqlDMOConn.Connect("(local)", "sa", "");

sqlDMOConn.AttachDB( "DM_0814_ABCTrucking", tmp );

When I do this, the AttachDB call raised the following exception
"Device Activation Error. The physical file name 'C:\Program' may be
incorrect."

I think what's happening is that SQLDMO doesn't like the space
character in the filenames. How can I formulate the file name
correctly?

--steve

Re: SQLDMO attachDB error with filenames including space character by n33470

n33470
Thu Aug 19 08:46:39 CDT 2004

I figured it out.

Here's a link to some additional info:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sqldmo/dmoref_con01_80j7.asp

The problem is that the string needs to be escaped in brackets in
order to correcly process the special characters in the filename. I
knew this had to be the solution, but I didn't know what the escape
sequence was!

--steve

n33470@hotmail.com (n33470) wrote in message news:<7bdcc156.0408181405.5cb908c9@posting.google.com>...
> Hey everyone!
>
> I'm trying to use SQLDMO to programmatically attach a database. I
> have a problem when the file name includes a space character, for
> example: @"C:\Program Files\Microsoft SQL
> Server\MSSQL\Data\DM_0814_ABCTrucking.mdf"
>
> Here's a sample of code:
>
> string tmp = @"C:\Program Files\Microsoft SQL
> Server\MSSQL\Data\DM_0814_ABCTrucking.mdf" +"," +@"C:\Program
> Files\Microsoft SQL Server\MSSQL\Data\DM_0814_ABCTrucking_log.ldf";
>
> SQLDMO.SQLServer sqlDMOConn = new SQLDMO.SQLServer();
>
> sqlDMOConn.Connect("(local)", "sa", "");
>
> sqlDMOConn.AttachDB( "DM_0814_ABCTrucking", tmp );
>
> When I do this, the AttachDB call raised the following exception
> "Device Activation Error. The physical file name 'C:\Program' may be
> incorrect."
>
> I think what's happening is that SQLDMO doesn't like the space
> character in the filenames. How can I formulate the file name
> correctly?
>
> --steve

Re: SQLDMO attachDB error with filenames including space character by Guest

Guest
Wed May 18 10:17:43 CDT 2005



> Hey everyone!
>
> I'm trying to use SQLDMO to programmatically attach a database. I
> have a problem when the file name includes a space character, for
> example: @"C:\Program Files\Microsoft SQL
> Server\MSSQL\Data\DM_0814_ABCTrucking.mdf"
>
> Here's a sample of code:
>
> string tmp = @"C:\Program Files\Microsoft SQL
> Server\MSSQL\Data\DM_0814_ABCTrucking.mdf" +"," +@"C:\Program
> Files\Microsoft SQL Server\MSSQL\Data\DM_0814_ABCTrucking_log.ldf";
>
> SQLDMO.SQLServer sqlDMOConn = new SQLDMO.SQLServer();
>
> sqlDMOConn.Connect("(local)", "sa", "");
>
> sqlDMOConn.AttachDB( "DM_0814_ABCTrucking", tmp );
>
> When I do this, the AttachDB call raised the following exception
> "Device Activation Error. The physical file name 'C:\Program' may be
> incorrect."
>
> I think what's happening is that SQLDMO doesn't like the space
> character in the filenames. How can I formulate the file name
> correctly?
>
> --steve

User submitted from AEWNET (http://www.aewnet.com/)

Re: SQLDMO attachDB error with filenames including space character by Guest

Guest
Wed May 18 10:18:26 CDT 2005


> Hey everyone!
>
> I'm trying to use SQLDMO to programmatically attach a database. I
> have a problem when the file name includes a space character, for
> example: @"C:\Program Files\Microsoft SQL
> Server\MSSQL\Data\DM_0814_ABCTrucking.mdf"
>
> Here's a sample of code:
>
> string tmp = @"C:\Program Files\Microsoft SQL
> Server\MSSQL\Data\DM_0814_ABCTrucking.mdf" +"," +@"C:\Program
> Files\Microsoft SQL Server\MSSQL\Data\DM_0814_ABCTrucking_log.ldf";
>
> SQLDMO.SQLServer sqlDMOConn = new SQLDMO.SQLServer();
>
> sqlDMOConn.Connect("(local)", "sa", "");
>
> sqlDMOConn.AttachDB( "DM_0814_ABCTrucking", tmp );
>
> When I do this, the AttachDB call raised the following exception
> "Device Activation Error. The physical file name 'C:\Program' may be
> incorrect."
>
> I think what's happening is that SQLDMO doesn't like the space
> character in the filenames. How can I formulate the file name
> correctly?
>
> --steve

User submitted from AEWNET (http://www.aewnet.com/)

Re: SQLDMO attachDB error with filenames including space character by Guest

Guest
Wed May 18 10:21:54 CDT 2005

> Hey everyone!
>
> I'm trying to use SQLDMO to programmatically attach a database. I
> have a problem when the file name includes a space character, for
> example: @"C:\Program Files\Microsoft SQL
> Server\MSSQL\Data\DM_0814_ABCTrucking.mdf"
>
> Here's a sample of code:
>
> string tmp = @"C:\Program Files\Microsoft SQL
> Server\MSSQL\Data\DM_0814_ABCTrucking.mdf" +"," +@"C:\Program
> Files\Microsoft SQL Server\MSSQL\Data\DM_0814_ABCTrucking_log.ldf";
>
> SQLDMO.SQLServer sqlDMOConn = new SQLDMO.SQLServer();
>
> sqlDMOConn.Connect("(local)", "sa", "");
>
> sqlDMOConn.AttachDB( "DM_0814_ABCTrucking", tmp );
>
> When I do this, the AttachDB call raised the following exception
> "Device Activation Error. The physical file name 'C:\Program' may be
> incorrect."
>
> I think what's happening is that SQLDMO doesn't like the space
> character in the filenames. How can I formulate the file name
> correctly?
>
> --steve

Hi,

You have jsut to put the string between [ and ] .
exp : yourstringPath = "[c:\\program files\\....]";
for more info go to this link: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sqldmo/dmoref_con01_80j7.asp

Ahmed Akrour.





User submitted from AEWNET (http://www.aewnet.com/)