问题
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