ImageVerifierCode 换一换
格式:DOCX , 页数:21 ,大小:20.90KB ,
资源ID:11402733      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/11402733.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(c#连接数据库代码集合.docx)为本站会员(b****8)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

c#连接数据库代码集合.docx

1、c#连接数据库代码集合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;

2、Server=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

3、Source 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

4、Library=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=Aron

5、1;Database=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

6、same 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

7、 the 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 SqlCon

8、nection()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 mor

9、e How 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

10、 Vines 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 conne

11、ctionstring 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. AttachDBF

12、ilename-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

13、to the 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 lifetim

14、e. Useful 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 ob

15、taining 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

16、 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. Integrated Security-or-Trusted_Connection false Whether the connection is to be a secure connection or not. Recognized values ar

17、e true, false, and sspi, which is equivalent to true. Max Pool Size 100 The maximum number of connections allowed in the pool. Min Pool Size 0 The minimum number of connections allowed in the pool. Network Library-or-Net dbmssocn The network library used to establish a connection to an instance of S

18、QL Server. Supported values include dbnmpntw (Named Pipes), dbmsrpcn (Multiprotocol), dbmsadsn (Apple Talk), dbmsgnet (VIA), dbmsipcn (Shared Memory) and dbmsspxn (IPX/SPX), and dbmssocn (TCP/IP). The corresponding network DLL must be installed on the system to which you connect. If you do not speci

19、fy a network and you use a local server (for example, . or (local), shared memory is used. Packet Size 8192 Size in bytes of the network packets used to communicate with an instance of SQL Server. Password-or-Pwd The password for the SQL Server account logging on. Persist Security Info false When se

20、t to false, security-sensitive information, such as the password, is not returned as part of the connection if the connection is open or has ever been in an open state. Resetting the connection string resets all connection string values including the password. Pooling true When true, the SQLConnecti

21、on object is drawn from the appropriate pool, or if necessary, is created and added to the appropriate pool. User ID The SQL Server login account. Workstation ID the local computer name The name of the workstation connecting to SQL Server. note Use ; to separate each property.If a name occurs more t

22、han once, the value from the last one in the connectionstring will be used.If you are building your connectionstring in your app using values from user input fields, make sure the user cant change the connectionstring by inserting an additional property with another value within the user value. Acce

23、ss ODBC standard Security:Driver=Microsoft Access Driver (*.mdb);Dbq=C:mydatabase.mdb;Uid=Admin;Pwd=; workgroup:Driver=Microsoft Access Driver (*.mdb);Dbq=C:mydatabase.mdb;SystemDB=C:mydatabase.mdw; exclusive:Driver=Microsoft Access Driver (*.mdb);Dbq=C:mydatabase.mdb;Exclusive=1;Uid=admin;Pwd= OLE

24、DB, OleDbConnection (.NET) standard security:Provider=Microsoft.Jet.OLEDB.4.0;Data Source=somepathmydb.mdb;User Id=admin;Password=; workgroup (system database):Provider=Microsoft.Jet.OLEDB.4.0;Data Source=somepathmydb.mdb;Jet OLEDB:System Database=system.mdw; with password:Provider=Microsoft.Jet.OLE

25、DB.4.0;Data Source=somepathmydb.mdb;Jet OLEDB:Database Password=MyDbPassword; Oracle ODBC new version:Driver=Microsoft ODBC for Oracle;Server=OracleServer.world;Uid=Username;Pwd=asdasd; old version:Driver=Microsoft ODBC Driver for Oracle;ConnectString=OracleServer.world;Uid=myUsername;Pwd=myPassword

26、; OLE DB, OleDbConnection (.NET) standard security:Provider=msdaora;Data Source=MyOracleDB;User Id=UserName;Password=asdasd; this ones from Microsoft, the following are from Oraclestandard Security:Provider=OraOLEDB.Oracle;Data Source=MyOracleDB;User Id=Username;Password=asdasd; trusted Connection:P

27、rovider=OraOLEDB.Oracle;Data Source=MyOracleDB;OSAuthent=1; OracleConnection (.NET) standard:Data Source=MyOracleDB;Integrated Security=yes; this one works only with Oracle 8i release 3 or laterspecifying username and password:Data Source=MyOracleDB;User Id=username;Password=passwd;Integrated Securi

28、ty=no; this one works only with Oracle 8i release 3 or laterdeclare the OracleConnection:C#:using System.Data.OracleClient;OracleConnection oOracleConn = new OracleConnection();oOracleConn.ConnectionString = my connectionstring;oOracleConn.Open(); VB.NET:Imports System.Data.OracleClientDim oOracleCo

29、nn As OracleConnection = New OracleConnection()oOracleConn.ConnectionString = my connectionstringoOracleConn.Open() missing the System.Data.OracleClient namespace? Download .NET Managed Provider for Oracle great article! Features of Oracle Data Provider for .NET by Rama Mohan G. at C# CornerCore Lab

30、s OraDirect (.NET) standard:User ID=scott; Password=tiger; Host=ora; Pooling=true; Min Pool Size=0;Max Pool Size=100; Connection Lifetime=0 Read more at Core Lab and the product page.Data Shape ms Data Shape:Provider=MSDataShape.1;Persist Security Info=False;Data Provider=MSDAORA;Data Source=orac;us

31、er id=username;password=mypw want to learn data shaping? Check out 4GuyfFromRollas great article about Data Shaping MySQL ODBC odbc 2.50 Local database:Driver=mySQL;Server=localhost;Option=16834;Database=mydatabase; odbc 2.50 Remote database:Driver=mySQL;Server=;Port=3306;Option=131072;Stmt=;Database

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1