如何通过app.config来连接mysql
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name ="conMysql"
connectionString="DataLayer=MySQL; Server=127.0.0.1; Database=nsytowel; User ID=root; Password=;" />
</connectionStrings>
</configuration>
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name ="conMysql"
connectionString="DataLayer=MySQL; Server=127.0.0.1; Database=nsytowel; User ID=root; Password=;" />
</connectionStrings>
</configuration>
<add name="abc" connectionString="data source=192.168.1.1;Initial Catalog=db;Max Pool Size=512;user id=sa;password=" />
</connectionStrings>
<add name="connStr" connectionString="server=hostName(ip); user id=user; password=password; database=dbName;" providerName="MySql.Data.MySqlClient"/>
</connectionStrings>
string dbConnectionString = ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString;
string dbProviderName = ConfigurationManager.ConnectionStrings["ConnStr"].ProviderName;
http://www.cnblogs.com/chy710/archive/2006/09/05/495000.aspx
/// 返回DataSet数据集
/// </summary>
/// <param name="strSql">SQL语句</param>
public DataSet GetDs(string strSql)
{
#region
try
{
Open();
sqlda = new MySQLDataAdapter(strSql, sqlcn);
ds = new DataSet();
sqlda.Fill(ds); //报错的断点处
Close();
return ds;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
throw new Exception("在执行操作时发生了异常。"+ex.Message.ToString());
}
finally
{
Close();
}
#endregion
}<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="conStr"
providerName="System.Data.SqlClient"
connectionString="server=.;database=nsytowel;Integrated Security=SSPI" />
<add name="conMysql"
connectionString="server=localhost;user id=root; password=; Database=nsytowel;CharacterSet =gb2312;"
providerName="MySql.Data.MySqlClient"/>
</connectionStrings>
</configuration>在执行操作时发生了异常。MySQLDriverCS Exception: MySQLDriverCS Error: wrong query.No database selected
<configuration>
<connectionStrings>
<add name="conMysql"
connectionString="Location=127.0.0.1;UserID=root;Password=;Data Source=nsytowel;CharacterSet =gb2312;"
providerName="System.Data.MySqlClient"/>
</connectionStrings>
</configuration>