app.config
<appSettings>
<add key="DBConnectionString" value="server=.\SQLEXPRESS;database=cdm;User Id=sa;pwd=123abc!"/>
</appSettings>
.cs
using System.Data.SqlClient;
using System.Configuration;
using (SqlConnection connection = new SqlConnection(ConfigurationSettings.AppSettings["DBConnectionString"]))
{
SqlCommand command = new SqlCommand("select max(spid) from spkfk ", connection);
command.Connection.Open();
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
}