Creating a File DSN

See Also

A file data source name (DSN) stores information about a database connection in a file. The file has the extension .dsn and by default is stored in the $\Program Files\Common Files\ODBC\Data Sources directory.

To create a new file DSN

  1. In the Project Explorer, right-click the database project you want to add a data connection to, and then select Add Data Connection.

    Note   In Microsoft® Visual C++®, right-click the database project in FileView.

  2. Select the File Data Source tab.

  3. Choose New.

  4. Select the driver for which you want to set up a data source, and then choose Next.

  5. Type a name for the file that will contain the connection information. Once created, this name will appear in the Select Data Source dialog box. The extension .dsn is automatically appended to the name that you type. When you have finished typing the name, choose Next.

  6. Review the information you have entered. If everything is correct, choose Finish. If you want to make changes, choose Back.

  7. Follow the instructions for the Create a New Data Source wizard or the dialog box that is displayed. For help with these dialog boxes, choose the Help button.

    For SQL Server data sources, you use the Create a New Data Source wizard. For other data sources, you use various dialog boxes. For example, for Microsoft® Access data sources, you use the ODBC Microsoft Access 97 Setup dialog box, and for Microsoft® FoxPro® data sources, you use the ODBC Visual FoxPro Setup dialog box.

    Tip   When you specify a database, enter a location that will work not only in the development environment you are using, but also in your final project. For example, if your project involves a database that is accessed from a Web server, use a Universal Naming Code (UNC) to be sure that the database location you specify is accessible from the Web server.

If you've created a file DSN for a server-based database, you will be prompted with the login dialog box for the database server. The values you enter into the login dialog box are used to build the connection string stored in the file DSN. If you specify a password in the login dialog box, you will be prompted for the password every time you log on to the database. If the account you use to log on to the database doesn’t have a password, you won't be prompted for a password when you log on again.

After you enter the necessary information in the login dialog box, the new file DSN is created. You are then returned to the File Data Source tab of the Select Data Source dialog box, which now includes the file DSN you've just created. You can then select a DSN and connect to the data source. The values you have already entered appear as the default values in the login dialog box.

Note   If you are developing a Web application in Microsoft® Visual InterDev™, you should create a file DSN to store the information needed to connect to your database. After you select or create a file DSN, you can add a data connection to the Web project or database project.

After you have added a data connection to your project, you no longer need the file DSN, because all of the necessary connection information is copied from the file DSN and stored with the Web application in the Global.asa file. This type of connection, which derives from a DSN but no longer relies upon it, is called a DSN-less connection. DSN-less connections are especially useful for Web applications because they enable you to move the application from one server to another without recreating the DSN on the new server.