How to Connect to SQL Server using LINQ to SQL?

后端 未结 3 1393
时光取名叫无心
时光取名叫无心 2021-01-31 10:04

Sure this is a really dumb question, but how do I connect my C# console app to a SQL Server Instance?

Have done this plenty of times with c# Web Apps, but this is the fi

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-31 10:35

    Step 1: Add a connection to your Server Explorer

    enter image description here

    After that is added, you should see it appear under the server exlporer tab on the left side of your screen.

    Step 2: Add a Linq to SQL file (.dbml) to your project

    enter image description here

    Step 3: Open the .dbml file from the file explorer on the right hand side of Visual Studio

    Step 4: Open up your connection via the drop down arrows on you server browser so that you can see the tables you which to use in your console app

    Step 5: Drag them onto the design area (as seen by the yellow lines and the result of doing this in the green box)

    enter image description here

    Step 6: Go back to your .cs page for your console, instantiate, and get to work

    enter image description here

    EDIT:

    My guess would be that you may be missing SQL server from your computer. Check your start menu, do you have Microsoft SQL Server folder with a configuration tool in it as seen here?:

    enter image description here

提交回复
热议问题