In the previous post, we were talking about creating servers, databases and tables using the Windows Azure portal. Now we will talk about developing it using ADO.NET.
First of all what do we need to start the development?
Your username, password, server name and database name.
Create the first connection string to the master database to be able to create other databases like the following:
SqlConnectionStringBuilder constrbuilder;
constrbuilder = new SqlConnectionStringBuilder();
constrbuilder.DataSource = dataSource;
constrbuilder.InitialCatalog = “master”;
constrbuilder.Encrypt = true;
constrbuilder.TrustServerCertificate = false;
constrbuilder.UserID = userName;
constrbuilder.Password = password;
Now you are able to create a new database like the one we did in the previous post but using the ASO.NET.
SqlConnection con = new SqlConnection(connString1Builder.ToString());
SqlCommand cmd = con.CreateCommand();
con.Open();
cmd.CommandText = string.Format(“CREATE DATABASE {0}”, databasename);
cmd.ExecuteNonQuery();
con.Close();
as the previous example as long as you have the data required to access the database you can normally do anything like the SQL server
SqlConnection con = new SqlConnection(constrbuilder.ToString());
SqlCommand cmd = con.CreateCommand();
cmd.CommandText = “ENTER ANY COMMAND YOU WOULD LIKE TO BE DONE ON YOUR DATABASE”;
cmd.ExecuteNonQuery();