string connetionString = null;
SqlConnection cnn;
cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["connection"].ConnectionString);
try
{
cnn.Open();
MessageBox.Show("Connection Open ! ");
cnn.Close();
}
catch (Exception ex)
{
MessageBox.Show("Can not open connection ! ");
}
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name="connection" connectionString="Data Source='OFFICE\SQLEXPRESS';Initial Catalog=market_data;Persist Security Info=True;User ID=sa;Password=xxxxx" providerName="System.Data.SqlClient" />
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>
No comments:
Post a Comment