link to a mdf database

olafurpetursson

Junior Member
May 24, 2017
1
0
1
So I created a MS SQL db , but now I cannot link to it.

I WOULD like to create a database in my C:/Cfusion/wwroot folder and not in ProgramFiles/MicsoSQL/Data folder.

Is that possible? How? I cannot create a new database in anywhere but ProgramFiles/MicsoSQL/Data folder.

Now I have an mdf in wwroot, but it does not show in enterprise manager?

This is bothering me because I need to select it so I can create a super user for it , and then an ODBC datasource so I can use it with coldfusion.

I think it needs to be in my wwwroot to work for coldfusion
 

KB

Diamond Member
Nov 8, 1999
5,396
383
126
You shouldn't need to care where the database is. You should just make a connection to SQL Server and specify the name of the database.

If you really want to put a database in a specific spot you can.
Do you have SQL Server Management Studio? Its a GUI that lets you create a database and you can pick the folder you want to put it in.
https://www.gfi.com/support/products/gfi-mailessentials/KBID003379

If not, you can also use OSQL (command line tool) to run TSQL to create the database in a specific folder:
https://docs.microsoft.com/en-us/sql/tools/osql-utility
https://docs.microsoft.com/en-us/sql/t-sql/statements/create-database-sql-server-transact-sql
 

morrishall

Junior Member
May 25, 2017
1
0
1
SQL Server does not behave the same way as Access. You do not connect to the MDF file. You connect to the server and select a database. The default location for the database files is (I think),

\Program Files\Microsoft SQL Server\MSSQL\Data,

though you can point a database to a different location when you create the database (either with Query Analyzer (QA) or Enterprise Manager (EM)).

Please look at "CREATE DATABASE" in the books online. If you are creating the database in EM, look at the "Location" box in the "Data Files" or "Transaction Log" tabs of the "Database Properties" box. I would highly recommend that you not put the mdf and ldf files anywhere in your web document tree. They should not be accessible from any URL. You might want to create a folder called "Data" under "Inetpub" for the SQL data files that is not world-readable.

If you wish to move a data file, then you need to detach the database, move the data file, and reattach the db (see "sp_detach_db" in Books Online). If the file is corrupted or doesn't open you, then you need a commercial product which shall remain nameless.

Probable file repair spam removed -- Programming Moderator Ken g6

As for ColdFusion, it comes with native SQL Server drivers that you should use instead of ODBC. On the datasources page, enter a name for your datasource (this can be anything, it's just a description to use in your CFQUERY's) and select Microsoft SQL Server as the type. Then, the database name is the name of your database in SQL Server, the server is the hostname or IP address running SQL Server (i.e. localhost) and the username and password are a SQL Server user name. Your SQL Server should be set for mixed-mode, and you should have created the user in EM with access to the database.
 
Last edited by a moderator:

Red Squirrel

No Lifer
May 24, 2003
67,347
12,100
126
www.anyf.ca
You want to be aware of where the DB is, and control where it is, so it can be put on proper raid storage, and you also don't want it to be part of the backup job (you don't want to backup the raw file, but have a separate tool actually do a dump). But that said to connect to it, the location does not matter. You also don't want it to be in your wwwroot folder because it will make it accessible to the public! Ensure it is in a place that is not part of the wwwroot or any other folder that will be published.