I have a problem with CREATE DATABASE statement, since it needs to specify the absolut path for a file in the FILENAME= option. I would need instead a relative path, i.e. only the name of the file because the script that launch this SQL command is dependant on the installation path decided by the user, during the installation.
Is there a way to pass to the FILENAME only the name of the file?
Hope to have been clear :-)
Thanks in advanceTry KB article 307283:How To Create a SQL Server Database Programmatically by Using ADO.NET and Visual C# .NET
Terri|||Hi, Terry
I have created a batch file that run the script sql for the creating the database, but in the option FILENAME if the path does not exist on the clients PC - the script will fail.
Any suggestions appreciated.
Thanks.
Fabio.|||I'm really sorry, I missed the "relative path" part of your question. As far as I know SQL Server cannot use a relative path for the filename.
I wonder if you could make use of one of the system or extended stored procedures sp_helpfile, master..xp_getfiledetails, sp_helpdevice?? Or perhaps use the undocumented stored procedure XP_REGREAD to read the installation path out of the registry?
Terri|||Hello,
I have exactly the same question.
I've got a ASP.NET application, where I want to automate the creation of the database for the Webmaster (once they fill in the appropriate SQL Server/MSDE Database Server location and login info, etc...).
My dynamically written CREATE DATABASE script wants a full absolute filepath for the Data and Log files.
And obviously I need to take into account the fact the Database Server may not be local to the Webserver.
I can't seem to find any easy way to find this information, other than to do a query of the "Master" database, like so:
--------
USE [Master]
SELECT filename
FROM sysfiles
WHERE (name = 'master')
--------
The above returns a value like "C:\Data\MSSQL\data\master.mdf".
From this I could easily extract just the directory path portion.
Am I crazy? Is this reliable?
Or is there a better way to get this information?
Any insight would be appreciated....