1 Replies - 458 Views - Last Post: 22 March 2011 - 08:11 AM

#1 marinus  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 138
  • View blog
  • Posts: 575
  • Joined: 14-April 10

Will this query work on another pc

Posted 22 March 2011 - 07:57 AM

Ok guys here is my scenario

i have this query in C#


                    string DBCreate =

                  " CREATE DATABASE " +
                               "MAIN_SETTINGS"
                               + " ON PRIMARY "
                               + " (NAME = Main_Settings , "
                               + " FILENAME =" + @"N'C:\\Program Files\\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\Main_Settings.mdf'" + ", "
                               + " SIZE = 2MB,"
                               + " FILEGROWTH =1024KB) "
                               + " LOG ON (NAME =Main_Log, "
                               + " FILENAME =" + @"N'C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\Main_Log.ldf'" + ", "
                               + " SIZE = 1MB, "
                               + " FILEGROWTH = 1024KB) ";


It creates a new database and it works :)

But look at FILENAME in query , i have the sneaky suspicion that if you will run this query on a pc with the drive name of D this code will crash , if so how to fix it


Also what does N' mean in this piece of code

N'C:\\Program Files\\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\Main_Settings.mdf


Thanks a million


Marinus

This post has been edited by marinus: 22 March 2011 - 07:59 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Will this query work on another pc

#2 Ionut  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 386
  • View blog
  • Posts: 1,057
  • Joined: 17-July 10

Re: Will this query work on another pc

Posted 22 March 2011 - 08:11 AM

N is used in the same idea of @ in C#. It tells the compiler to treat ' as single character part of string
Example:
instead of
INSERT INTO Table VALUES ('O''Neill')


you can put
INSERT INTO Table VALUES (N'O'Neill')



About your situation, you can go with:
1. a path defined by you where you want to create the database. To keep the database on the same partition with the operating system is a bad idea because tempdb's size depends on how many transactions are rolled on server and the amount of that is queried. I saw situation when the server(physical machine) freezed because tempdb had 40gb and there was no space for OS on C:\ drive.
2. use environment variables to get the path.
Environment.GetVariable("windir")


returns C:\Windows or D:\Windows

Basically, I recommand to see what drives are available and install on the one with most free space.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1