Tuesday, March 1, 2011

How to move the LINQ - dbml file to production server.

Usually we know that the dbml acts as an interface  between the database and user interface for getting connected with the database.

We create the dbml file in our development system and itz quite obvious that the dbml file will directly point to our development database.

What if we move our application into to the production server there the database server will be pointing to the different location. So we need to manually write a code to point to the production database.

Here is the steps which you need to follow.

1. Open the LINQ project.

2. Open the Properties in that go to the file Settings.settings -> Settings.designer.cs file.

        [global::System.Configuration.DefaultSettingValueAttribute("Data Source=SIVA-HOME\\SQL2005;Initial Catalog=Inventory;Persist Securi" +
            "ty Info=True;User ID=sa;Password=2121212")]

        public string FreeFlockServiceConnectionString {
            get {
//this is the place which concerns us, this is value which is auto generated
//this is auto-generated by the dbml file
               // return ((string)(this["FreeFlockServiceConnectionString"]));

//create a code which point to the database from the web.config
                return ((string)(System.Configuration.ConfigurationManager.ConnectionStrings["FreeFlockServiceConnectionString"].ConnectionString));

3. Create a connection string tag in the web.config which is pointing to the production server database.

<add name="FreeFlockConnectionString" connectionString="Data Source=eti-sqlserver\SQL2005;Initial Catalog=FreeFlockDevSvr;UID=sa;password=courage920nw" />

Thatz cool rite!!!!

1 comment:

  1. What about moving dbml from one solution to another? I just added a dbml file (.dbml, .layout, .vb) from one solution to another and the .vb file part of it came over without the DataContext and I think that's the reason I can't create an instance of the DataContext class in the target solution. Trying to figure out how to resolve that.