开发者

How do I connect to my local SQL instance in Visual Studio?

I开发者_JAVA百科've installed VS2010 Express and all associated SQL. I've got an instance running on my local machines of .\sqlexpress and I can connect to it with SSMS. I've created some tables etc.

I want to use Linq to SQL so I have created a new empty .dbml file in my solution. I assume the next step is to connect to the database, but I don't know how as I've never done this before.

I tried Add Connection as it suggests, and the Data Source I can choose Access Database, SQL Server Compact 3.5 or SQL Server Database File.

The Database File one says, "use it to connect to a local instance", so I click that. Then it asks for a database file name, new or existing. Surely I should be typing in the instance name not doing this file thing? If I do type something in, it crease a .mdf in my documents folder and it doesn't really help me much.

Any ideas how I can get this to work?


it's easier than you think.

  1. you create a new database in SQL Management Studio, you call it whatever, myDatabase...
  2. from Visual Studio you select the SQL Provider and you select the local instance and the myDatabase as db name.

everything is basically as you said except that you should have created a database and you should then select it in VS.

doing this from a new EF model, VS will store the connection string compatible with EF format in the app.config so you will be able to check it and see how such connection string is written.


I finally figured this out via a blog post or two somewhere online. With the express edition, the option to connect to a local database in the normal way via IP or ./sqlexpress is not present. You have to connect using a File, by finding the .mdf file on your hard disk (within the SQL server folder somewhere) that represents your database, and selecting it.

I have no idea what happens if you update your database schema in SSMS, or why they've restricted it to this bizarre method, but it works and I have been able to query my database.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜