0% found this document useful (0 votes)
46 views

SQL SErver Connection Dot NET

The document provides instructions for starting the default SQL Server instance and connecting to a SQL Server database from a .NET application. It describes starting SQL Server from the Start menu and SQL Server Configuration Manager. It also provides steps for creating a database and table, writing a stored procedure, and configuring the connection string and code to connect to the database and execute the stored procedure to retrieve and display data in the .NET application.

Uploaded by

Gadilkar Vishal
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views

SQL SErver Connection Dot NET

The document provides instructions for starting the default SQL Server instance and connecting to a SQL Server database from a .NET application. It describes starting SQL Server from the Start menu and SQL Server Configuration Manager. It also provides steps for creating a database and table, writing a stored procedure, and configuring the connection string and code to connect to the database and execute the stored procedure to retrieve and display data in the .NET application.

Uploaded by

Gadilkar Vishal
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 3

To start the default instance of SQL Server

1. On the Start menu, point to All Programs, point to Microsoft SQL


Server, and then click SQL Server Configuration Manager.

2. In SQL Server Configuration Manager, expand Services, and then click


SQL Server.

3. In the details pane, right-click SQL Server (MSSQLServer), and then


click Start.

4. A green arrow on the icon next to the server name and on the toolbar
indicates that the server started successfully.
5. Now you can create your own database(ex. name it 'MyDatabaseName' ) .

Add tables to it.

write store procedure to access data from thoes tables.(ex. name it


'spPlanTransportSelect' )

Then In your .Net project in web.config file write following lines to


connect to the SQL Server database:

<configuration>

<connectionStrings>

<remove name=”LocalSqlServer”/>

<add name="MyConnectionString" connectionString="Data Source=localhost; Initial


Catalog=MyDatabaseName; Integrated Security=True"
providerName="System.Data.SqlClient"/>

</connectionStrings>

</configuration>

Then In your .Net project on the code behind form use class
provided by microsoft for connection by :

import System.Data.SqlClient;

Then in your function write following lines to connect and use it:
string connectionString =
WebConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString;
SqlConnection conn = new SqlConnection(connectionString);

SqlDataAdapter dta = new SqlDataAdapter();


DataSet ds = new DataSet();

conn.Open();

SqlCommand sqlSelect = new SqlCommand("spPlanTransportSelect", conn);


sqlSelect.CommandType =CommandType.StoredProcedure;

dta.SelectCommand = sqlSelect;
dta.Fill(ds, "PlanTransport");

if(conn.State != ConnectionState.Closed)

conn.Close();

Here DataSet ds will conten the data return by database.

You might also like