Create Database in a different Server | from command line using osql command

  • Hi,

    I am using the following script for creating the DB

    CREATE DATABASE ['+@DatabaseName+'] ON PRIMARY

    ( NAME = N'''+@DatabaseName+''', FILENAME = N'''+@FilePath+@FileName+'.mdf'' , SIZE = 60416KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )

    LOG ON

    ( NAME = N'''+@DatabaseName+'_log'', FILENAME = N'''+@FilePath+@FileName+'__log.ldf'' , SIZE = 688384KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)

    COLLATE SQL_Latin1_General_CP1_CI_AS

    If the file path "@FilePath" is a local drive then the database is creating in local machine. If I given the filepath in a different network like \\bangkkosur\d$\LSRDB\ then I am getting the following errors

    Msg 5110, Level 16, State 2, Line 7

    The file "\\bangkkosur\d$\\LSRDB\DATA\LSRDB_Jul 29 2008 .mdf" is on a network path that is not supported for database files.

    Msg 1802, Level 16, State 1, Line 7

    CREATE DATABASE failed. Some file names listed could not be created. Check related errors.

    I am calling this DB creation script using osql option from command line. I am having administrative power on the remote machile. I can create folders and files from my local command line on the remote machine....

    Please help me out for resolving this... Or any other waya are available t create the DB on a different machine from commandline of some other machines?,....

    Thanks in advance..

    -Aneesh

  • Hi calltoaneesh,

    If you execute the above statement then you are trying to create a database locally with database files in a remote machine,

    In OSQL you have the switch -S which is used to specify the server name, and using this you can specify the path relative to that server

    OSQL -S then execute the sql stmt using the -I option or the T-Sql stmt directly.

    Remember that remote connections are enabled in that computer.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply