Skip to content

Instantly share code, notes, and snippets.

@ChrisMoney
Last active June 8, 2024 19:14
Show Gist options
  • Save ChrisMoney/9cb132d97758951a2d1df8db2dd97ba3 to your computer and use it in GitHub Desktop.
Save ChrisMoney/9cb132d97758951a2d1df8db2dd97ba3 to your computer and use it in GitHub Desktop.
Azure Query
// Global vars
private SqlConnection _connection;
SqlConnectionStringBuilder conn = new SqlConnectionStringBuilder();
//Azure SQL Server Name
conn.DataSource = "mssqltipsserver.database.windows.net";
//User to connect to Azure
conn.UserID = "admindaniel";
//Password used in Azure
conn.Password = "mypws@#&*234!";
//Azure database name
conn.InitialCatalog = "mymssqltips";
private SqlTransaction _transaction;
static int GetData()
{
try
{
//Query used in the code
String sql = "SELECT name,costrate,availability from dbo.location";
//Connect to Azure SQL using the connection
using (SqlCommand sqlcommand = new SqlCommand(sql, _connection))
{
//Open the connection
_connection.Open();
_transaction.Begin();
// call DAO
DAOClass daoClass = new DAOClass(_connection, _transaction);
daoClass.GetData();
}
}
}
//If it fails write the error message exception
catch (SqlException e)
{
//Write the error message
Console.WriteLine(e.ToString());
}
Console.ReadLine();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment