Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

c# - Cant find my EF code first database

I am doing Microsoft's MVC getting started tutorial:

Getting Started with Entity Framework 6 Code First using MVC 5.

This includes the creation of a code first database.

It all works fine, but I am not able to find my database.

This is my ConnectionString:

<add name="MovieDBContext" connectionString="Data Source=.SQLEXPRESS; Integrated Security=True" providerName="System.Data.SqlClient"/>

If I debug my index Method the connection is as follow:

Data Source=.SQLEXPRESS; Integrated Security=True

But there is no Database in my SQLEXPRESS Instance, I have checked it with SQL Server Management Studio.

I also cant find anything if I search my filesystem for *.mdf.

App_Data in my Project is Empty...

But all CRUD operations are working fine, there has to be something.

The only way I can see that table is to connect to .SQLEXPRESS via the Visual Studio Server Explorer. But where is this physically located? Why cant I see the table if I connect to .SQLEXPRESS via SQL Server Management Studio?

Any idea?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You didn't specify the Initial Catalog in your connection string so probably you are using the Master database.

You need to specify the Initial catalog like this:

<add name="MovieDBContext" 
     connectionString="Data Source=.SQLEXPRESS;Initial Catalog=yourDBName;Integrated Security=True" 
     providerName="System.Data.SqlClient"/>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...