无需连接字符串代码先改变数据源 [英] Code-First change data source without connection string

查看:108
本文介绍了无需连接字符串代码先改变数据源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎有一个问题,创造,我都采用代码优先的方法来创建我的模型,但没有连接字符串似乎在web.config文件中创建一个应用程序MVC4

I seem to have an issue creating an MVC4 application where I have adopted the code-first approach to creating my models but no connection string seems to have been created in the web.config file.

构建的数据库似乎是建立在(本地主机)\SQLEXPRESS实例,但我想改变这外部数据源。如果没有一个连接字符串来更新我不知道如何做到这一点。

The constructed database seems to have been built on (localhost)\SQLEXPRESS instance but I would like to change this to an external data source. Without a connection string to update I'm not sure how to do this.

请可能有人点我在正确的方向?

Please could someone point me in the right direction?

编辑:我发现下面的图,突出什么答案都表示非常好

推荐答案

您必须添加一个连接字符串自己

You have to add a connection string yourself

<add name="SomeDb" connectionString="Data Source=SERVENAME;Initial Catalog=DBNAME;User Id=loginid;Password=password" providerName="System.Data.SqlClient" />

该字符串的名称应与你的上下文类的名称。

Name of this string should match to the name of your context class.

public class SomeDb: DbContext
{
    public SomeDb()
        : base("name=SomeDb")
    { 
    }
}

这应该这样做。

这篇关于无需连接字符串代码先改变数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆