搜尋此網誌

2011年7月8日 星期五

各種資料庫 SQL 連接字串

OleDbConnection conn = new OleDbConnection(connectString);
代碼:
<add key="SQLConnString" value="Provider=SQLOLEDB;Data Source=192.168.100.20;Initial Catalog=BCH_Gamania_TW;User Id=sa;Password=;Connection Timeout=10"/>
string connectString = WebConfigurationManager.AppSettings["SQLConnString"].ToString().Trim();
SqlConnection conn = new SqlConnection(connectString);

代碼:
<add key="ConncetionString" value="Data Source=192.168.100.20;Initial Catalog=BCH_Gamania_TW;Persist Security Info=True;User ID=sa;Password=; Connection Timeout=10" />
string connectString = WebConfigurationManager.AppSettings["ConncetionString"].ToString().Trim();
SqlCeConnection sqlCeConn = new SqlCeConnection(sqlCeStr);


代碼:
static string gstrPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
static string sqlCeStr = "Data Source='" + gstrPath + "\\PDA_Gamania_TW.sdf'; Password='13126930'; Encrypt = TRUE;";

當連接資料庫需要加上埠號時 , 只需在IP後加上 ' , ' 埠號 .
代碼:
value="Data Source=192.168.100.20,1433

沒有留言:

張貼留言