Last post Aug 28, 2017 05:04 AM by Zhi Lv - MSFT
Aug 24, 2017 09:09 AM|polachan|LINK
At the moment I am creating the select list from the ShiftApp database which is the default database of the project. But in one place in program the selectlist of the employee code should be from different database in different server.
My web.config is as given below
<add name="ShiftAppEntities" connectionString="metadata=res://*/DB.ShiftAppModel.csdl|res://*/DB.ShiftAppModel.ssdl|res://*/DB.ShiftAppModel.msl;provider=System.Data.SqlClient;provider connection string="data source=REC-707\SQLEXPRESS;initial catalog=ShiftApp;integrated
security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
Please can you guide me how can I call the employee Select list from Different server REC-705\ SQLEXPRESS;initial catalog=PayRoll in the selectlist statement
public ActionResult Create()
ViewBag.EmployeeCode = new SelectList(db.tblEmployees.Where(x => x.id > 0).ToList(), "Id", "EMPREF");
Aug 24, 2017 11:38 AM|ignatandrei|LINK
just modify in the web.config the connection string
Aug 24, 2017 11:43 AM|polachan|LINK
I think it is not a solution to modify web.config. I am using the connection string and it is the database of my application. I want to bring all the employee code and name from different database in different server to the current database. So I need
to show a SelectList of employee from the other server database
Anyway Many thanks
Aug 24, 2017 07:41 PM|DA924|LINK
You can't go to another DB from a model that is dedicated to a DB. The only thing you can do is make a new folder/namespace and create a new model for the other DB, which means you'll have two connectionstrings.
Aug 28, 2017 05:04 AM|Zhi Lv - MSFT|LINK
Agree with DA924, I suppose the easiest way is to add multiple connection string in the web.config file, then, according to the connection string to add two dbcontext in the project.
Such as below:
<!-- Very basic Connection String Examples -->
<add name="ConnectionA" connectionString=ServerA"; Initial Catalog=DatabaseA; Integrated Security=True"/>
<add name="ConnectionB" connectionString=ServerB"; Initial Catalog=DatabaseB; Integrated Security=True"/>
If you require some additional information on Connection Strings and writing them in general, please check the following article: