我在關注本教程: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
中做過。我這樣說只是爲了知道這些字段不爲空