我在关注本教程:http://msdn.microsoft.com/en-us/data/jj193542的Code First
基本使用ADO.NET EF
。问题是,执行代码时DataBase不是自动创建的,我认为这是因为我的app.config
中的配置,但这是我第一天使用真实代码,我无法弄清楚如何调整我的配置文件,所以我可以连接到我的服务器并根据需要使用创建的数据库,或者让本教程中的程序按照预期创建新数据库。ADO.NET EF - 无法使用VS2010建立数据库连接
这是我App.config
文件:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<entityFramework>
<!-- <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory> -->
<connectionStrings>
<add name="BloggingContext"
providerName="System.Data.SqlClient"
connectionString="server=milka-pc\sqlserver2012;Database=Panorama;user id=MyID;password=MyPass;port=3333;Integrated Security=True;"/>
</connectionStrings>
<!--<contexts>
<context type=" Blogging.BloggingContext, MyAssembly">
<databaseInitializer type="Blogging.MyCustomBlogInitializer, MyAssembly" />
</context>
</contexts>-->
</entityFramework>
</configuration>
正如你可以看到,我尝试了各种各样的事情,使工作某些部分评论。
这是服务器资源管理器如何Ÿ样子,而我试图连接:
而且因为我有零经验ViasualStudioXXXX和连接到数据库,这是我所看到的和我如何选择我的服务器:
有在milka-pc\sqlserver2012
我有一个名为DB Panorama
,我可以使用或更好的按照教程一步一步一步离开程序来创建我的新数据库。现在我不能这两个。并连接到milka-pc\sqlserver2012
我需要提供UserName
和Password
,我在App.config
中做过。我这样说只是为了知道这些字段不为空