How To : Connecting to an SQL Database
Contents |
[edit] Description
This document describes how to add an SQL project to a solution and connect the project to a MySQL or PostgreSQL database. You also have the option to have a MySQL sandbox automatically provisioned for testing.
[edit] Prerequisites
Introduction to Bungee Builder
Introduction to Working with SQL Databases
[edit] Whitelisting Your Hosted Database
If you want to connect to a MySQL or PostgreSQL database hosted on the web, you will need to have the DNS name %.bungeegrid.com whitelisted to allow connection.
[edit] Procedure
To add and connect an SQL project:
- In the Solution Explorer, right-click on the solution and select Add Project.
- In the dialog box that's displayed, do the following:
- Select SQL Project. Click Next.
- In Name, type a name for the project (the default is SQL Project).
- Select MySQL, PostgreSQL or Sandbox (MySQL Database)
- If you chose MySQL, under Settings, configure this project to connect to a database.
- For Host, type the URL where your database is being hosted (do not include the http://).
- For Database, type the name of the database to which you want to connect.
- For User, type the username for connecting to this database.
- For Password, type the password for connecting to this database.
- For Port, type the port number for the port you want to use to connect to this database (MySQL uses 3306 by default).
- (Optional) Click Test Connection to test the settings you have entered before you add the project.
- Click Done.
- If you chose PostgreSQL, under Settings, configure this project to connect to a database.
- For Host, type the URL where your database is being hosted (do not include the http://).
- For Database, type the name of the database to which you want to connect.
- For User, type the username for connecting to this database.
- For Password, type the password for connecting to this database.
- For Port, type the port number of the port you want to use to connect to this database (PostgreSQL uses 5432 by default).
- (Optional) Click Test Connection to test the settings you have entered before you add the project.
- Click Done.
- If you chose Sandbox, under Settings, all the settings are automatically set for you. Click OK.
- The project is added to the solution.
To interact with the SQL database at design time:
- In the Solution Explorer, expand your SQL project.
- Expand MySQL or Postgres, depending on which type of database your project is connected to.
- For a MySQL database, MySQL Databases, shows all the databases available in the current connection.
- For a Postgres database, the Database name is shown.
- Double-click SQL Console. This opens the SQL Console in the Design Editor.
In the SQL Console, you can execute sql queries on your database.
- Config allows you to change the configuration setting of the connection for the project.
[edit] Error Handling
[edit] Examples
[edit] Next Steps
Creating a Class to Contain Row Data from an SQL Table
Logging in to an SQL Database
Adding CRUD Operations to a Class
Using SQL Query Escaping
Debugging SQL
Adding a Class to a Project
Adding a Function to a Class
Adding a Field to a Class
Adding a Form to a Class
[edit] Tags
Categories: HOW TO | MySQL | PostgreSQL | Database