I am developing a SharePoint 2013 custom WebPart using Visual Studio 2012 where on Page_Load event, I am calling a method RunProc() which executes a SQL Stored Procedure in some other server. When I deploy the solution (.wsp) and test in my Dev environment, it runs fine but while deploying the .wsp in another environment (say test/prod), I need to modify the Connection String as Server name will change accordingly. Providing a separate .wsp for each environment is not an affordable solution. Can anyone help me on how to configure this Connection String dynamically so that I can modify it accordingly before deploying it to a specific environment?
Here is the code snippet for a better understanding. The variable in question is the string variable connStr in the method RunProc()
protected void Page_Load(object sender, EventArgs e)
{
if !(Page.IsPostBack)
{
RunProc();
}
}
protected void RunProc()
{
string connStr = @"Data Source=MyServer;Initial Catalog=MyDB;Integrated Security=SSPI;Persist Security Info=False";
SqlConnection conn = new SqlConnection(connStr);
SqlCommand com = new SqlCommand("[dbo].[RunJobStatus]", conn);
com.CommandType = CommandType.StoredProcedure;
conn.Open();
com.ExecuteNonQuery();
conn.Close();
}
0 commentaires:
Enregistrer un commentaire