Connect EF to SQL Server Management studio

时间秒杀一切 提交于 2019-12-13 21:50:08

问题


I'm using EF code-first and I want it to create the new database in SQL Server Management Studio instance instead of using the integrated SQL Server in Visual Studio.

I added this to my web.config:

<connectionStrings>
    <add name="BillFo" 
         connectionString="Data Source=SELANL293;Initial Catalog=Billfo;Integrated Security=True"/>
</connectionStrings>

But it doesn't help. No nothing happens, nothing in the integrated SQL Server and nothing in my SQL Server Management Studio. How do I make it create my database in Management Studio rather then the SQL Server in Visual Studio?


回答1:


try add this section

  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="connection string......"/>
      </parameters>
    </defaultConnectionFactory>
  </entityFramework>


<connectionStrings>
    <add name="..." providerName="System.Data.SqlClient" connectionString="......" />
  </connectionStrings> 

you do not have to use <parameters> property , you can use your currently connection string configuration




回答2:


Try

<connectionStrings>
    <clear />
    <add name="YourEFContextName" connectionString="Data Source=localhost\SqlServerInstanceName; Initial Catalog=DataBaseName; User ID=UserName; password=YourPassword; MultipleActiveResultSets=True;" providerName="System.Data.SqlClient" />
</connectionStrings>

The section entityFramework should be created automatically.



来源:https://stackoverflow.com/questions/25348508/connect-ef-to-sql-server-management-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!