ADO.NET<数据库连接总汇>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Data.OleDb;
using System.Data.Odbc;
namespace SqlCon
{
    class Program
    {
        static void Main(string[] args)
        {
            //本地 SQL Server 数据源  集成安全的链接字符串(Integrated security=SSPI)
            string sqlConnectString1 = "Data Source=(local);" + "Integrated security=SSPI;Initial Catalog=Student;";
            using (SqlConnection con1 = new SqlConnection(sqlConnectString1))
            {
                con1.Open();
                Console.WriteLine("----.net data provider for sql server----");
                Console.WriteLine("State={0}",con1.State);
                Console.WriteLine("DataSoure={0}",con1.DataSource);
                con1.Close();
            }
            //本地 SQL Server 数据源 不集成安全的字符串(User Id=sa;Password=password)
            string sqlConnectString2 = "Data Soure=(local);" + "User Id=sa;Password=password;Initial Catalog=Student;";
            using (OleDbConnection con2 = new OleDbConnection(sqlConnectString2))
            {
                con2.Open();
                Console.WriteLine("\n----.net data provider for sql server----");
                Console.WriteLine("State={0}",con2.State);
                Console.WriteLine("DataSoure={0}",con2.DataSource);
                con2.Close();
            }
               
            //OLE DB 数据源
            string oledbConnectString="Provider=SQLOLEDB;Data Soure=(local);"+"Initial Catalog=Student;User Id=sa;Password=password;";
            using(OleDbConnection con3=new OleDbConnection(oledbConnectString))
            {
                con3.Open();
                Console.WriteLine("\n----.net data provider for OLE DB----");
                Console.WriteLine("State={0}",con3.State);
                Console.WriteLine("DataSoure={0}",con3.DataSource);
                con3.Close();
            }
            //ODBC 数据源
            string odbcConnectString = "Drive={SQL Native Client};" + "Server=(local);Database=Student;uid=sa;pwd=password;";
            using(OdbcConnection con4=new OdbcConnection(odbcConnectString))
            {
                con4.Open();
                Console.WriteLine("\n----.net data provider for ODBC----");
                Console.WriteLine("State={0}",con4.State);
                Console.WriteLine("DataSoure={0}",con4.DataSource);
                con4.Close();
            }
            Console.WriteLine("\nPress any key to continue.");
            Console.ReadKey();
        }
    }
}


知识共享许可协议
《ADO.NET<数据库连接总汇>》常伟华 创作。
采用 知识共享 署名-相同方式共享 3.0 中国大陆 许可协议进行许可。
  • 多说评论
  • 签名
  • 新浪微博
  • 默认评论
  • Tab Header 5

0 条评论 / 点击此处发表评论

Tab Content 5

开发技术


开发平台和工具

sitemap     155.88ms