Generate connection string dynamically in ASP.NET MVC

≯℡__Kan透↙ 提交于 2019-12-13 10:36:01

问题


I am calling a stored procedure in a static class and calling that in my controller, which will generate connection string on the fly in my Asp.NET MVC project. I am calling like this:

var connection = App.connectionstring.connectionstring.connection().ToString();

Here var connection has the connection string. Now I need to use this connection and connect to database.

I followed EntityConnectionStringBuilder() approach like this:

var builder = new EntityConnectionStringBuilder();
      builder.Metadata = "res://*/MyModel.csdl|res://*/MyModel.ssdl|res://*/MyModel.msl";
      builder.Provider = "System.Data.SqlClient";
      builder.ProviderConnectionString = connection;

But I am not sure whether it's the correct implementation and also I don't know how to use this connection string in the web.config or somewhere to connect to database.

Can someone help me in this.

来源:https://stackoverflow.com/questions/22043235/generate-connection-string-dynamically-in-asp-net-mvc

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