數據庫連接字符串從配置文件讀取。
代碼
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Data.Common;
using System.Collections.Generic;
namespace Maticsoft.DBUtility
{
/// <summary>
/// 數據訪問抽象基礎類
/// </summary>
public abstract class DbHelperSQL
{
// <?xml version="1.0" encoding="utf-8" ?>
// <configuration>
// <appSettings>
// <!--連接主程序的字符串-->
// <add key="connection" value="server=CONTRON-CAD9158;uid=sa;pwd=sa;database=syt"/>
// <!---->
// <add key="connectionzt" value="server=CONTRON-CAD9158;uid=sa;pwd=sa;database=syt_qwerthjkl"/>
// <!--連接主SQLServer 的字符串-->
// <add key="ConnectServer" value="server=CONTRON-CAD9158;uid=sa;pwd=sa;database=master"/>
// <!--建立數據庫的連接字符串-->
// <add key="connInit" value="data source=CONTRON-CAD9158;user id=sa;password=sa;persist security info=false;packet size=4096"/>
// <!--SQLServer安裝目錄-->
// <add key="sqlServerData" value="C:Program FilesMicrosoft SQL ServerMSSQLData"/>
// </appSettings>
// </configuration>
//數據庫連接字符串(web.config來配置),可以動態更改connectionString支持多數據庫.
public static string connectionString = PubConstant.ConnectionString;
public static string connectionString = System.Configuration.ConfigurationSettings.AppSettings["connection"];
public