1

I use data connections to connect to a SQL Server 2008 Database. I search the web to know how to open, close and do queries (CRUD) but I found nothing.

enter image description here

In a first time, I would open a connection. I am stuck because I don't know how to get my connection "object" and use it in C# code.

Here is the begining of my code :

SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["Connection"].ConnectionString);

Thanks in advance !

Anwar
  • 4,162
  • 4
  • 41
  • 62

2 Answers2

3

You do not. This explorer is a developer tool to use in visual studio. It has no resemblance at all to what you do in your C# code.

TomTom
  • 61,059
  • 10
  • 88
  • 148
3

You can't use the database from the Server Manager. Instead include the database in your Solution Explorer. However you will still need the database to be in the Server Manager in order to use it in your Solution Explorer. You can add it to your Solution Explorer by right clicking on Solution Explorer and go to add -> new item.

J. Steen
  • 15,470
  • 15
  • 56
  • 63
Dave
  • 434
  • 5
  • 22
  • 1
    You can get the full correct connection string by right-clicking your project in the Solution Explorer, the selecting add -> new item -> ADO.NET Entity Data Model -> EF Designer from data... . The next screen shows the connection string used. – Fuzzy Analysis Apr 14 '19 at 08:27