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