Can I Create and Link to an MDF Database in a Specific Folder for ColdFusion?

  • Thread starter Thread starter BjornPorgilsson
  • Start date Start date
  • Tags Tags
    Database Link
Click For Summary
Creating a Microsoft SQL database in a custom location, such as the C:/Cfusion/wwroot folder, is not straightforward. SQL Server typically stores database files in the default directory, which is Program Files/Microsoft SQL Server/Data. While it is possible to specify a different location during database creation in SQL Server Management Studio (SSMS) or through SQL commands, it is not advisable to place database files within the web server's document root for security reasons. To link the database with ColdFusion, it is essential to configure a data source in ColdFusion, using the native SQL Server drivers rather than ODBC. This involves providing the database name, server address, and user credentials in the ColdFusion data source setup. If the MDF file is already created in the wwroot but not visible in Enterprise Manager, it may need to be detached, moved, and reattached to the SQL Server instance. Proper user permissions and mixed-mode authentication should also be ensured for successful database access.
BjornPorgilsson
Messages
3
Reaction score
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
 
  • Like
Likes morrishall
Technology news on Phys.org
Guys, can help me? I would be grateful for any advice.
 
BjornPorgilsson said:
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

When you create a web application you must have a web server and a database server. You put your web pages - or parts of the web application that are used / served by the web server in general, in the root folder of your web server (following some tree structure) and you create connections to the database server, in order to request content. Now, in order to work with ColdFusion and IIS (and any other web server for that matter), ColdFusion server takes the SQL content of the cfquery tag and passes it to the specified driver of the data source. So, you have to configure data source first. For how to do this take a look here. The data files for the database server are kept in the database server.

Also, if you want to take a look at some basics of ColdFusion - in case you don't know ColdFusion (although not very popular any more) here is an interesting link.
 
  • Like
Likes BjornPorgilsson
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.
 
  • Like
Likes BjornPorgilsson
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 mdf opener.

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.
 
  • Like
Likes BjornPorgilsson
Thank you all for your advice! I'm appreciative for your responses and help.
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

  • · Replies 50 ·
2
Replies
50
Views
8K
Replies
5
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 11 ·
Replies
11
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
Replies
2
Views
2K
  • · Replies 24 ·
Replies
24
Views
10K
  • · Replies 7 ·
Replies
7
Views
1K
  • · Replies 5 ·
Replies
5
Views
2K
Replies
4
Views
5K