In my first post on SQL Azure (
SQL Azure: A First Contact) I talked about how you can access SQL Azure using SQL Server 2008 Management Studio (SSMS).
In this post, the journey continues with “walking” on the cloud using
ADO .NET :)
Here’s the recipe!
Ingredients
- A valid SQL Azure CTP account
- Visual Studio 2008 SP1
- .NET Framework 3.5 SP1
- C# (or respective VB.NET) namespace: System.Data.SqlClient
Objects used from System.Data.SqlClient namespace:
- SqlConnection
- SqlCommand
- SqlDataReader
- SqlDataAdapter
Process
- Step 1: Add namespace for using SqlClient
- Step 2: Set up connection to database
- Step 3: Open database connection
- Step 4: Set the T-SQL command(s) - Use the "SqlCommand" object
- Step 5: Open the SqlDataReader - Execute the T-SQL command(s)
- Step 6: Display the results (if any)
- Step 7: Close the SqlDataReader
- Step 8: Close the database connection
Source Code (for obvious reasons I removed the connection string from the source code file)
- You can find the sample source code for this post here.
- *Note: This sample code is for demo purposes and does not represent production code.
Considerations
- My example is based on the example in my previous post on SQL Azure (Database Name: sqlazure, table name: CLOUD_MSGS)
- For this post I used a new Visual C# “Console Application” project named ADO .NET – SQL Azure like in the following screenshot:
Screenshot of the output
Have fun!
Drop me a comment if you need any help implementing the ADO.NET connection to SQL Azure!