c#连接数据库代码集合

上传人:xmg****18 文档编号:121221570 上传时间:2020-02-19 格式:DOC 页数:32 大小:54KB
返回 下载 相关 举报
c#连接数据库代码集合_第1页
第1页 / 共32页
c#连接数据库代码集合_第2页
第2页 / 共32页
c#连接数据库代码集合_第3页
第3页 / 共32页
c#连接数据库代码集合_第4页
第4页 / 共32页
c#连接数据库代码集合_第5页
第5页 / 共32页
点击查看更多>>
资源描述

《c#连接数据库代码集合》由会员分享,可在线阅读,更多相关《c#连接数据库代码集合(32页珍藏版)》请在金锄头文库上搜索。

1、.专业整理.SQL Server ODBC standard Security:Driver=SQL Server;Server=Aron1;Database=pubs;Uid=sa;Pwd=asdasd; trusted connection:Driver=SQL Server;Server=Aron1;Database=pubs;Trusted_Connection=yes; prompt for username and password:oConn.Properties(Prompt) = adPromptAlwaysoConn.Open Driver=SQL Server;Serve

2、r=Aron1;DataBase=pubs; OLE DB, OleDbConnection (.NET) standard Security:Provider=sqloledb;Data Source=Aron1;Initial Catalog=pubs;User Id=sa;Password=asdasd; trusted Connection:Provider=sqloledb;Data Source=Aron1;Initial Catalog=pubs;Integrated Security=SSPI; (use serverNameinstanceName as Data Sourc

3、e to use an specifik SQLServer instance, only SQLServer2000)prompt for username and password:oConn.Provider = sqloledboConn.Properties(Prompt) = adPromptAlwaysoConn.Open Data Source=Aron1;Initial Catalog=pubs; connect via an IP address:Provider=sqloledb;Data Source=190.190.200.100,1433;Network Libra

4、ry=DBMSSOCN;Initial Catalog=pubs;User ID=sa;Password=asdasd; (dbmssocn=tcp/ip instead of Named Pipes, at the end of the Data Source is the port to use (1433 is the default)SqlConnection (.NET) standard Security:Data Source=Aron1;Initial Catalog=pubs;User Id=sa;Password=asdasd; - or -Server=Aron1;Dat

5、abase=pubs;User ID=sa;Password=asdasd;Trusted_Connection=False (booth connection strings produces the same result)trusted Connection:Data Source=Aron1;Initial Catalog=pubs;Integrated Security=SSPI; - or -Server=Aron1;Database=pubs;Trusted_Connection=True; (booth connection strings produces the same

6、result)(use serverNameinstanceName as Data Source to use an specifik SQLServer instance, only SQLServer2000)connect via an IP address:Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial Catalog=pubs;User ID=sa;Password=asdasd; (dbmssocn=tcp/ip instead of Named Pipes, at the end of the

7、Data Source is the port to use (1433 is the default)declare the SqlConnection:C#:using System.Data.SqlClient;SqlConnection oSQLConn = new SqlConnection();oSQLConn.ConnectionString=my connectionstring;oSQLConn.Open(); VB.NET:Imports System.Data.SqlClientDim oSQLConn As SqlConnection = New SqlConnecti

8、on()oSQLConn.ConnectionString=my connectionstringoSQLConn.Open() Data Shape ms Data ShapeProvider=MSDataShape;Data Provider=SQLOLEDB;Data Source=Aron1;Initial Catalog=pubs;User ID=sa;Password=asdasd; want to learn data shaping? Check out 4GuyfFromRollas great article about Data Shaping Read more How

9、 to define which network protocol to useExample:Provider=sqloledb;Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial Catalog=pubs;User ID=sa;Password=asdasd; Name Network library dbnmpntw Win32 Named Pipes dbmssocn Win32 Winsock TCP/IP dbmsspxn Win32 SPX/IPX dbmsvinn Win32 Banyan Vine

10、s dbmsrpcn Win32 Multi-Protocol (Windows RPC) important note! When connecting through the SQLOLEDB provider use the syntax Network Library=dbmssocnand when connecting through MSDASQL provider use the syntax Network=dbmssocn All SqlConnection connectionstring propertiesThis table shows all connection

11、string properties for the ADO.NET SqlConnection object. Most of the properties are also used in ADO. All properties and descriptions is from msdn. Name Default Description Application Name The name of the application, or .Net SqlClient Data Provider if no application name is provided. AttachDBFilena

12、me-or-extended properties-or-Initial File Name The name of the primary file, including the full path name, of an attachable database. The database name must be specified with the keyword database. Connect Timeout-or-Connection Timeout 15 The length of time (in seconds) to wait for a connection to th

13、e server before terminating the attempt and generating an error. Connection Lifetime 0 When a connection is returned to the pool, its creation time is compared with the current time, and the connection is destroyed if that time span (in seconds) exceeds the value specified by connection lifetime. Us

14、eful in clustered configurations to force load balancing between a running server and a server just brought on-line. Connection Reset true Determines whether the database connection is reset when being removed from the pool. Setting to false avoids making an additional server round-trip when obtaini

15、ng a connection, but the programmer must be aware that the connection state is not being reset. Current Language The SQL Server Language record name. Data Source-or-Server-or-Address-or-Addr-or-Network Address The name or network address of the instance of SQL Server to which to connect. Enlist true When true, the pooler automatically enlists the connection in the creation threads current transaction context. Initial Catalog-or-Database The name of the database.

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 教学/培训

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号