C#,连接数据库字符串汇总

//-------------------SQL Server连接数据库字符串-------------20161216-----------------------------
Data Source=服务器地址; Initial Catalog=数据库名;User ID=sa;Password=sa


//-------------------ACCESS连接数据库字符串----------20161216-----------------------------
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=data.accdb     连接没加密数据库存字符串
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=data.accdb;Jet OLEDB:Database Password=123456    连接加密数据库存字符串
注释:data.accdb   ACCESS文件 直接这样写为程序根目录

//--------------------SQLite连接字符串-----20171031-------------------
Data Source= address.db;Pooling=true;FailIfMissing=false 
注释:address.db为Sqlite文件,这样写为程序的根目录


//--------------------Oracle连接字符串-----20180506-------------------

data source = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = IP地址)(PORT = 端串口号默认的是1521)))(CONNECT_DATA = (SERVICE_NAME = 实体名))); User ID = 帐号; Password = 密码; Pooling = True; Max Pool Size = 10; Min Pool Size = 1;

//--------------------Mysql连接字符串-----20210714-------------------
Database=lqwvje;Data Source=192.168.0.105;User Id=root;Password=12345678;pooling=false;CharSet=utf8;port=3306
/// <summary>
///SQL Server  测试数据是否连接    20180522
/// </summary>
/// <param name="connStr">连接字符串</param>
/// <returns></returns>
public string TestConnection(string connStr)
{
    try
    {
        //SqlConnection是SQL server  OleDbConnection是Access不同的数据库不一样
        using (SqlConnection connection = new SqlConnection(connStr))
        {
            connection.Open();
            if (connection.State.ToString().Contains("Open"))
            {
                return "连接成功";
            }
            else
            {
                return "未连接成功";
            }
        }
    }
    catch (Exception ex)
    {
        return ex.Message;
    }
}