MySqlConnection m_conn = new MySqlConnection()
m_conn.ConnectionString =
string.Format("Data Source={0}Initial Catalog={1}Persist Security Info=TrueUser ID={2}Password={3}", server, dbname, sqluser, sqlpass
)
m_conn.Open()
m_conn.Close()
这是复制我自己项目里的代码。。。
建一个组件,继承Installer[RunInstaller(true)]
public class InstallClass:Installer
{
public override void Install(System.Collections.IDictionary stateSaver)
{
//写你的导入代码
}
}
最后做安装包的时候,把这个组件作为主输出包进去,就ok
首先引用MySql.Data.dll
给出一个例子。
///
<summary>
///
运行查询
///
</summary>
///
<param
name="sql">单点查询语句</param>
///
<returns>DbDataReader数据阅读器</returns>
///
<exception
cref="ConnectionException">
///
如果打开连接失败,或者运行的语句不正确则抛出连接异常
///
YuanHeng.Product.EHotel.BusiLayer.DAO.ConnectionException
///
</exception>
public
MySqlDataReader
ExecuteQueryToRead(string
sql)
{
try
{
using
(MySqlConnection
connection
=
new
MySqlConnection(this.MySqlConnectionStr))
{
connection.Open()
log.Debug("ExecuteQueryToRead
->
"
+
sql)
MySqlCommand
cmd
=
new
MySqlCommand(sql,
connection)
cmd.CommandType
=
CommandType.Text
return
cmd.ExecuteReader()
}
}
catch
(MySqlException
ex)
{
log.Error(ex.Message,
ex)//记录异常
throw
new
ConnectionException("Sql其它异常"
+
ex.Message)
}
catch
(Exception
e)
{
log.Error(e.Message,
e)//记录异常
throw
new
ConnectionException("其它异常"
+
e.Message)
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)