本地提供程序的性能一般比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/