c# - how to change connection string db value app setting to web config -
currently mvc project.previous developer database connected app settings change web config
i have changed code appsettings webconfig
<appsettings> <add key="tickportalsql" value="server=1.34.34.4.;database=montage;user id=montage;password=pwd;trusted_connection=false;" /> </appsettings>
this code change web config
<connectionstrings> <add key="tickportalsql" value="server=1.34.34.4.;database=montage;user id=montage;password=pwd;trusted_connection=false;" /> </connectionstrings>
previous developer using appsettingsreader
public abstract class homesqldbrepository { public string connectionstring { get; set; } = appsettingsreader.readstring("thenna"); const int maxitemcount = 1000; public enum sqlexecutetype { scalar, nonquery, reader } public async task<string> executesqlasync(string procname, sqlexecutetype executiontype, idictionary<string, string> parameters) { string ret = ""; using (sqlconnection sqlconn = new sqlconnection(connectionstring)) { using (sqlcommand sqlcmd = new sqlcommand(procname, sqlconn)) { sqlcmd.commandtype = commandtype.storedprocedure; foreach (keyvaluepair<string, string> kvp in parameters) { sqlcmd.parameters.addwithvalue(kvp.key, kvp.value); } sqlconn.open(); if (executiontype == sqlexecutetype.scalar) ret = (await sqlcmd.executescalarasync()).tostring(); else if (executiontype == sqlexecutetype.nonquery) ret = (await sqlcmd.executenonqueryasync()).tostring(); sqlconn.close(); } } return ret; }
but getting error ex exception here code
using microsoft.azure; public static class appsettingsreader { public static string readstring(string key) { try { return cloudconfigurationmanager.getsetting(key).tostring(); } catch(system.exception ex) { throw ex;//error } } public static int readint(string key) { try { return int.parse(cloudconfigurationmanager.getsetting(key).tostring()); } catch (system.exception ex) { throw ex; } } public static decimal readdecimal(string key) { try { return decimal.parse(cloudconfigurationmanager.getsetting(key).tostring()); } catch (system.exception ex) { throw ex; } } public static bool readbool(string key) { try { return bool.parse(cloudconfigurationmanager.getsetting(key).tostring()); } catch (system.exception ex) { throw ex; } } }
any 1 tell how change azure app settings read db web config db read? have tired many method getting error ..
change web.config to:
<connectionstrings> <add name="tickportalsql" value="server=1.34.34.4.;database=montage;userid=montage;password=pwd;trusted_connection=false;" /> </connectionstrings>
and access string
var connectionstring = configurationmanager.connectionstrings["tickportalsql"].connectionstring;
Comments
Post a Comment