[Company Logo Image] 

Home Up Contents Coffee Break Credits Glossary Links Search

 
How to connect to AdventureWorks on SQL Azure using C#

 

 

Home
Analysis Services
Azure
CLR Integration
High Availability
Open Source
Security
SQL Server 2008
SQL Server 2012
SQL Server 2014
SQL Server 2016
SQL Server 2017
SQL Server 2019
Tips
Troubleshooting
Tuning

How to connect to AdventureWorks on SQL Azure using C#


On this opportunity we are demonstrating how to connect to an AdventureWorks sample database located on a SQL Azure Database server using a Visual C# console application.

This demonstration has the following requirements:

bulletIt requires Visual Studio 2015 (Community Edition).
bulletIt requires AdventureWorks sample database installed on a SQL Azure Database server as explained here.


Let's start by opening Visual Studio and creating a new project using a Visual C# console application. Provide a name for the project.






Below is a small program we took from an official Azure tutorial to test connection to a SQL Azure database.

On the connection string the Server parameter holds the name of the SQL Azure database server separated of the TCP port 1433 with a comma.






Scrolling to the right we can see more parameters of the connection string like the Database parameter, where we need to specify the name of the database created on the database server mentioned above. In this case, the name of the database is AdventureWorks.

Next we need to specify the User Id and Password of a login with permissions to access the database.






The Encrypt and TrustServerCertificate parameters are described on this article.

The last parameter is the connection timeout parameter that is always related to the amount time a connection waits to time out.






Let's test connection to the Azure database as shown below.






If the connection is successful, below is the expected result.






References.


Connect to SQL Database by using .NET (C#)

 

 

 

.Send mail to webmaster@sqlcoffee.com with questions or comments about this web site.