webconfig:
<connectionStrings>
<add name="DbConn" connectionString="server=.;database=database;uid=sa;pwd=123456" providerName="System.Data.SqlClient" />
</connectionStrings>
配置链接:
using SqlSugar;
namespace Abcd.DAL
{
public class SqlSugarHelper
{
public static string ConnectionString = ConfigurationManager.ConnectionStrings["DbConn"].ToString();
public static SqlSugarClient _db = null;//SqlSugar对象,所有的操作都在: _db 里 . 出来
public static SqlSugarClient CretClient()
{
_db = new SqlSugarClient(new ConnectionConfig()
{
ConnectionString = ConnectionString, //必填,连接字符串
DbType = DbType.SqlServer, //必填,数据库类型
IsAutoCloseConnection = true,
MoreSettings = new ConnMoreSettings()
{
IsWithNoLockQuery = true
}
});
_db.Ado.CommandTimeOut = 300;//链接超时时间,单位秒
return _db;
}
}
}
调用:
string sql =" ... ";//略
var db = SqlSugarHelper.CretClient();//创建sqlSugar对象
int i = db.Ado.ExecuteCommand(sql);//执行sql语句
SqlSugar官网: https://www.donet5.com/Home/Doc