THE SQL SERVER PROGRAMMING MODEL connection string

THE SQL SERVER PROGRAMMING MODEL connection string for SQL Server strConn = Provider=SQLOLEDB;Data Source=myServer; + _ Initial Catalog=pubs;User Id=uid;Password=pwd; connection string for Oracle strConn = Provider=MSDAORA;Data Source=ora;User Id=scott; + _ Password=tiger; open the connection Provider is specified in connection string oConn.Open strConn oCmd.Connection = oConn Listing 4-2: Connections in ADO.NET //connection to SQL Server //data provider is not specified in connection string string sqlConn = server=localhost;database=pubs;uid=sa;pwd=6#B5p; ; //create an instance of SqlClient IDbConnection conn = new SqlConnection(sqlConn); conn.Open(); IDbCommand cmd = conn.CreateCommand(); //connection to Oracle using managed OLE DB provider string oraConn = Provider=MSDAORA;Data Source=ora; User Id=scott; Password=tiger; IDbConnection conn = new OleDbConnection(oraConn); IDbCommand oCmd = conn.CreateCommand(); conn.Open(); In .NET, then, how do we achieve generic data access, given that we have different providers? The actual data provider portion is factored into common interfaces IDbConnection, IDbCommand, IDataReader, and so on which are being implemented by the providers and exposed by a series of provider-specific classes: SqlConnection, OleDbConnection, SqlCommand, OleDbReader, and so on. You code against the interfaces rather than the data-source-specific classes, and the only time you need to specify a database-specific class is when you open the connection. Factory classes and common base classes are added in .NET 2.0. This programming

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost PHP Web Hosting services

Bookmark the permalink.

Comments are closed.