How would you connect to database using .NET?



How would you connect to database using .NET?..

Answer / Sanjay Kumar Joshi

To connect to a database using .NET, you can use the `SqlConnection` class for SQL Server. Here's an example:

```csharp
string connectionString = "Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword";
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
// Now you can perform database operations
}
```
Replace the `connectionString` values with your actual server address, database name, username, and password.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More ADO.NET Interview Questions

What we do with the object of ado.net dataset after using it?Can we dispose it or can we set it nothing?Is it must or not?

4 Answers   SVI,


What are the Different layers in ADO.Net?

7 Answers  


What is dataset and tell about its features. What are equivalent methods of previous, next etc. Of ADO in ADO.NET ?

1 Answers   Digital GlobalSoft,


How will you fill the gridview by using datatable object at runtime?

1 Answers  


Can we connect two dataadapters to same data source using single connection at same time?

1 Answers  


What are the different layers of ado.net?

1 Answers  


How to add an aggregate column?

1 Answers  


What are the different namespaces used in the project to connect the database?

3 Answers  


What is untyped dataset?

1 Answers  


Execute nonquery returns no. of afected rows.So if my stored procedure hav lot of select stmnt, delete stmnt, insert stmnt..then what does execute nonquery returns in this case?

6 Answers   Wipro,


Difference between ADO and ADO.Net

4 Answers   IBM,


What are the advantages and drawbacks of using ado.net?

1 Answers  


Categories