In the previous Tutorial we discussed about the database creation in SQL server management studio.
Create a windows form project. And add a button control.
This tutorial is to understand how you can test that the connection between sql server database and c# application in built or not. what you have to do is to use the using system.Data.sqlclient; .net library for the interaction with sql database.
next is the coding section. There are many different ways for passing the sql connection string in your application. I have used the simplest way to do so .Below is the code for the connection string.
// .net library contains the sql connection class and lots of other classes
private void btnConnection_Click(object sender, EventArgs e)
// replace the sql server name in data source according to ur PC Name
string sql = @"Data Source=Ali-PC;Initial Catalog=umbrellaTestDatabase; Password=sa; Integrated Security=true;";
// built in sqlConnection class in .net
// con is the object of the class and sql string is passed to the connection class
SqlConnection con = new SqlConnection(sql);
// con.open means the connection is setablished according to the above passed string between sql server and
// C# application.
// checking if the connection is established is true than execute the statement else move to the further statement in else part
if (con != null)
MessageBox.Show("Connecton built successfully ");
MessageBox.Show("Connection is not established");
The source code is provided Here . Thanl You