I have create a stored procedure with VB.NET
This procedure goes to a remote Server (for the moment on my near server Win 2003) until now everything are ok
The procedure is created and i call her from my program
The name is sp_AddStreamDB
mycommand = new sqlcommand("EXEC sp_AddStreamDB 'C:\sqlDATA\', 'RemoteDB'",RemoteSQLConn)
myCommand.ExecuteNonQuery()
Normally the procedure will take the two parameters and she put them in there own right places to executed, but that is not Happen
CREATE PROCEDURE [dbo].[sp_AddStreamDB] (
-- Add the parameters for the stored procedure here
@DPath varchar(max)
,@DBName varchar(50)
,@Qchar varchar(1) = "'"
)
AS
BEGIN_TRY:
SET QUOTED_IDENTIFIER ON ;
SET NOCOUNT ON ;
-- Insert statements for procedure here
DECLARE @ErrMsg nvarchar(4000)
,@DBName1 varchar(50)
,@DBName2 varchar(50)
,@DBNamefs varchar(50)
,@DBNamelog varchar(50)
,@FileGroupN varchar(100)
,@DATName varchar(max)
,@LOGName varchar(max)
,@FSName varchar(max)
SET @DBName1 = ( @DBName + '1' )
SET @DBName2 = ( @DBName + '2' )
SET @DBNamefs = ( @DBName + 'fs' )
SET @DBNamelog = ( @DBName + 'log' )
SET @FileGroupN = ( @DBname + 'StreamGroup' )
SET @DATName = ( @Qchar + @DPath + @DBName + '_dat.mdf' + @Qchar )
SET @LOGName = ( @Qchar + @DPath + @DBName + '_log.ldf' + @Qchar )
SET @FSName = ( @Qchar + @DPath + @DBName + '_fs' + @Qchar )
BEGIN_CATCH:
SELECT ERROR_MESSAGE() AS ErrorMessage ;
SELECT @ErrMsg = ERROR_MESSAGE()
CREATE DATABASE DBName
ON PRIMARY
(
NAME = DBName1
,FILENAME = DATName
),
FILEGROUP FileGroupN CONTAINS FILESTREAM
(
NAME = DBNamefs
,FILENAME = FSName
)
LOG ON
(
NAME = DBNamelog
,FILENAME = LOGName
)
RAISERROR (@ErrMsg,1,1)
RETURN 0
END_CATCH:
END_TRY:
=====================
CREATE DATABASE is the important issue
This procedure gives me an error "The File Name 'DATName' is not in the right format ....."
The varable @DATName is 'C:\sql\DATA\RemoteDB.dat.mdf'
( i have check this by PRINT @DATName and it is OK
But for some reason the line CREATE DATABASE refused to take the value of the variable and takes just the name (only the name) DATName which tries to excecute the name as value and of course that returns me the error
NOW
IS THERE ANYBODY WHICH CAN ASSIST ME ON THIS ISSUE?
After some troubleshooting tips i've change my code to this:
PRINT @DATName
CREATE DATABASE [@DBName]
ON PRIMARY
(
NAME = '@DBName1'
,FILENAME = '@DATName'
),
FILEGROUP [@FileGroupN] CONTAINS FILESTREAM
(
NAME = '@DBNamefs'
,FILENAME = '@FSName'
)
LOG ON
(
NAME = '@DBNamelog'
,FILENAME = '@LOGName'
)
and i'm taking the error: A file activation error occurred. The physical file name '@DATName' may be incorrect. Diagnose and correct additional errors, and retry the operation. CREATE DATABASE failed. Some file names listed could not be created. Check related errors.
Of course the @DATName is that:
'C:\sqlDATA\RemoteDB_dat.mdf'
The same i take it when i remove the brackets And the same i take it when i remove the single quotes
Lefteris Gkinis [email protected] 0030 22960 32843