// Connection string
// Method 1-
<add name="DBConnection" providerName="System.Data.SqlClient" connectionString="server=127.0.0.1;database=DBName;user=UserID;password=Pwd/>
// Method 1-
public static string MainDBName()
{
string conName = "";
using (SqlConnection
conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DBConnection"].ToString()))
{
conName=
conn.Database.ToString();
conName = conn.DataSource.ToString();
}
return conName;
}
// Method 2-
public static SqlConnectionStringBuilder SSB = new SqlConnectionStringBuilder(ConfigurationManager.ConnectionStrings["DBConnection"].ToString());
public static string server = Convert.ToString(SSB["server"]);
public static string database = Convert.ToString(SSB["database"]);
public static string UserID = Convert.ToString(SSB["user"]);
public static string password = Convert.ToString(SSB["password"]);
No comments:
Post a Comment