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

本地提供程序的性能一般比OLE DB或者ODBC提供程序更为出色,因为它是特地为这种数据库所设计的,并且它在应用程序和数据库之间消除了一个间接层。

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();
        }
    }
}

关于C# Oracle数据库的连接,比较麻烦,可以查看一下博客:

http://learningtips.blog.163.com/blog/static/165218332011789388317/

转载于:https://www.cnblogs.com/Ninac/archive/2013/04/11/3015585.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值