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 !

2
  • 1
    Is it me or did you forgot to add the code beneath: 'Here is the begining of my code:' Commented Nov 19, 2014 at 13:20
  • 1
    Yep, added the code missing. Commented Nov 19, 2014 at 13:28

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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.
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.