How to Connect Your ASP.NET Website to a Database Using Plesk Panel and FTP Print

  • Updated on 07-May-2024
  • 66

Developing an ASP.NET website often involves integrating it with a database to store and manage your data. This can initially seem daunting, especially if you're new to this. However, with a bit of guidance, it's a straightforward process. In this guide, we'll walk you through the steps to connect your ASP.NET website to a database using Plesk Panel and FTP on our ASP.NET hosting service.

Connecting ASP.NET Website to Database via Plesk Panel

Step 1: Create a Database in Plesk Panel

Log into your Plesk Panel. Navigate to the "Databases" section under your domain name. Click on the "Add Database" button, give your database a name, and then create a user with a secure password. Remember these details, as you'll need them in the next step.

Step 2: Connect to the Database in your ASP.NET Code

Now you need to modify your ASP.NET code to connect to your database. In your web.config file, you need to add your connection string in the <connectionStrings> section. The format is as follows:

<add name="MyDbConnString" connectionString=";Database=yourDbName;User Id=yourUsername;Password=yourPassword;" providerName="System.Data.SqlClient" />

Replace "MyDbConnString", "", "yourDbName", "yourUsername", and "yourPassword" with the appropriate values.

Connecting ASP.NET Website to Database via FTP

If you're not using Plesk Panel, you can still connect your ASP.NET site to a database by modifying your web.config file via FTP.

Step 1: Get your Database Connection Details

Log into your hosting control panel and navigate to your database management section. You'll find your database name, username, password, and server name here. Keep a note of these details.

Step 2: Update your Web.Config File via FTP

Use an FTP client (like FileZilla) to connect to your server. Navigate to your ASP.NET project, find the web.config file, and download it. Open the file and add the following code in the <connectionStrings> section:

<add name="MyDbConnString" connectionString=";Database=yourDbName;User Id=yourUsername;Password=yourPassword;" providerName="System.Data.SqlClient" />

Don't forget to replace "MyDbConnString", "", "yourDbName", "yourUsername", and "yourPassword" with your actual database details. Save the file, upload it to the server using your FTP client, and overwrite the existing web.config file.


Testing the Connection:

  1. Create a test page in your ASP.NET site (e.g., test.aspx) to check the database connection.
  2. On the test page, add the following code:
string connectionString = ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString;
SqlConnection connection = new SqlConnection(connectionString);
Response.Write("Database connection successful!");
  1. Upload the test.aspx file to your website's root directory using Plesk Panel's File Manager or FTP.



And there you have it! Whether using Plesk Panel or FTP, you've learned how to connect your ASP.NET website to a database on your shared Windows hosting server. This crucial skill will allow you to create more dynamic and interactive websites. If you have any more questions or need further help, please get in touch with our support team. Happy coding!

Was this answer helpful?

« Back