数据库连接字符串大全

合集下载

VBA编程中的数据库连接与操作详解

VBA编程中的数据库连接与操作详解

VBA编程中的数据库连接与操作详解VBA(Visual Basic for Applications)是一种用于编写Microsoft Office 应用程序的编程语言。

在VBA编程中,与数据库的连接和操作是非常重要的一部分。

本文将详细介绍VBA编程中的数据库连接和操作,并提供一些实例来帮助读者更好地理解。

一、数据库连接1. 连接字符串数据库连接通常需要使用连接字符串来指定数据库的位置和其他连接参数。

连接字符串的格式取决于所使用的数据库类型。

下面是一些常见数据库的连接字符串示例:- Access数据库:Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\myFolder\myDatabase.accdb;Persist SecurityInfo=False;- SQL Server数据库:Provider=SQLOLEDB;DataSource=serverName;Initial Catalog=databaseName;UserID=userName;Password=password;- MySQL数据库:Driver={MySQL ODBC 5.3Driver};Server=serverAddress;Database=databaseName;User=user ;Password=password;Option=3;需要注意,以上示例中的连接字符串仅供参考,实际使用时应根据具体情况进行修改。

2. 打开连接在VBA中,可以使用ADODB(ActiveX Data Objects)对象来进行数据库操作。

首先需要创建一个ADODB.Connection 对象,并使用连接字符串来打开连接。

下面是一个示例:```vbaDim conn As ObjectSet conn = CreateObject("ADODB.Connection")conn.ConnectionString ="Provider=Microsoft.ACE.OLEDB.12.0;DataSource=C:\myFolder\myDatabase.accdb;Persist SecurityInfo=False;"conn.Open```在打开连接之前,可以根据需要设置连接对象的其他属性,如CommandTimeout(执行命令的超时时间)和CursorLocation(指定游标的位置)等。

SQL server 和MySQL的 connectionstring大全

SQL server 和MySQL的 connectionstring大全

【SQL SERVER】Standard SecurityData Source=myServerAddress;Initial Catalog=myDataBase;UserId=myUsername;Password=myPassword;Standard Security alternative syntaxThis connection string produces the same result as the previous one. The reason to include it is to point out that some connection string keywords have many equivalents.Server=myServerAddress;Database=myDataBase;UserID=myUsername;Password=myPassword;Trusted_Connection=False;Trusted ConnectionData Source=myServerAddress;Initial Catalog=myDataBase;IntegratedSecurity=SSPI;Trusted Connection alternative syntaxThis connection string produce the same result as the previous one. The reason to include it is to point out that some connection string keywords have many equivalents.Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;Use serverName\instanceName as Data Source to use a specific SQL Server instance. Please note that the multiple SQL Server instances feature is available only from SQL Server version 2000 and not in any previous versions.Connecting to an SQL Server instanceThe syntax of specifying the server instance in the value of the server key is the same for all connection strings for SQL Server.Server=myServerName\theInstanceName;Database=myDataBase;Trusted_Connection=T rue;Trusted Connection from a CE deviceOften a Windows CE device is not authenticated and logged in to a domain. To use SSPI or trusted connection / authentication from a CE device, use this connection string.Data Source=myServerAddress;Initial Catalog=myDataBase;IntegratedSecurity=SSPI;User ID=myDomain\myUsername;Password=myPassword;Note that this will only work on a CE device.Read more about connecting to SQL Server from CE devices hereConnect via an IP addressData Source=190.190.200.100,1433;Network Library=DBMSSOCN;InitialCatalog=myDataBase;User ID=myUsername;Password=myPassword;Specifying packet sizeServer=myServerAddress;Database=myDataBase;UserID=myUsername;Password=myPassword;Trusted_Connection=False;Packet Size=4096; By default, the Microsoft .NET Framework Data Provider for SQL Server sets the network packet size to 8192 bytes. This might however not be optimal, try to set this value to 4096 instead.The default value of 8192 might cause errors as well ("Failed to reserve contiguous memory"), check this outMicrosoft OLE DB Provider for SQL Serv erType: OLE DB ProviderUsage:Provider=sqloledbManufacturer: MicrosoftMore info about this provider »Customize stringexample values »Standard SecurityProvider=sqloledb;Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;Trusted connectionProvider=sqloledb;Data Source=myServerAddress;InitialCatalog=myDataBase;Integrated Security=SSPI;Use serverName\instanceName as Data Source to use a specific SQL Server instance. Please note that the multiple SQL Server instances feature is available only from SQL Server version 2000 and not in any previous versions.Connecting to an SQL Server instanceThe syntax of specifying the server instance in the value of the server key is the same for all connection strings for SQL Server.Provider=sqloledb;Data Source=myServerName\theInstanceName;InitialCatalog=myDataBase;Integrated Security=SSPI;Prompt for username and passwordThis one is a bit tricky. First set the connection object's Provider property to "sqloledb". Thereafter set the connection object's Prompt property to adPromptAlways. Then use the connection string to connect to the database.oConn.Provider = "sqloledb"oConn.Properties("Prompt") = adPromptAlwaysData Source=myServerAddress;Initial Catalog=myDataBase;Connect via an IP addressProvider=sqloledb;Data Source=190.190.200.100,1433;NetworkLibrary=DBMSSOCN;Initial Catalog=myDataBase;UserID=myUsername;Password=myPassword;DBMSSOCN=TCP/IP. This is how to use TCP/IP instead of Named Pipes. At the end of the Data Source is the port to use. 1433 is the default port for SQL Server.How to define which network protocol to useDisable connection poolingThis one is usefull when receving errors "sp_setapprole was not invoked correctly." (7.0) or "General network error. Check your network documentation" (2000) when connecting using an application role enabled connection. Application pooling (or OLE DB resource pooling) is on by default. Disabling it can help on this error.Provider=sqloledb;Data Source=myServerAddress;Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword;OLE DB Services=-2;.NET Framework Data Provider for OLE DBType: .NET Framework Wrapper Class LibraryUsage:System.Data.OleDb.OleDbConnectionManufacturer: MicrosoftMore info about this wrapper class library »Customize stringexample values »Bridging to OLE DB Provider for SQL ServerThis is just one connection string sample for the wrapping OleDbConnection class that calls the underlying OLEDB provider. See respective OLE DB provider for more connection strings to use with this class.Provider=SQLOLEDB;Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername; Password=myPassword;Microsoft SQL Server ODBC DriverType: ODBC DriverUsage:Driver={SQL Server}Manufacturer: MicrosoftCustomize stringexample values »Standard SecurityDriver={SQLServer};Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPass word;Trusted connectionDriver={SQLServer};Server=myServerAddress;Database=myDataBase;Trusted_Connection=Yes;Prompt for username and passwordThis one is a bit tricky. First you need to set the connection object's Prompt property to adPromptAlways. Then use the connection string to connect to the database.oConn.Properties("Prompt") = adPromptAlwaysDriver={SQL Server};Server=myServerAddress;Database=myDataBase;SQL Server Native Client 10.0 OLE DB ProviderType: OLE DB ProviderUsage:Provider=SQLNCLI10Manufacturer: MicrosoftMore info about this provider »Customize stringexample values »Standard securityNote that the SQL Server Native Client OLE DB Provider does not support SQL Server 7.0. Provider=SQLNCLI10;Server=myServerAddress;Database=myDataBase;Uid=myUsername; Pwd=myPassword;Trusted connectionProvider=SQLNCLI10;Server=myServerAddress;Database=myDataBase;Trusted_Connection=yes;Equivalent key-value pair: "Integrated Security=SSPI" equals "Trusted_Connection=yes"Connecting to an SQL Server instanceThe syntax of specifying the server instance in the value of the server key is the same for all connection strings for SQL Server.Provider=SQLNCLI10;Server=myServerName\theInstanceName;Database=myDataBase; Trusted_Connection=yes;Prompt for username and passwordThis one is a bit tricky. First you need to set the connection object's Prompt property to adPromptAlways. Then use the connection string to connect to the database.oConn.Properties("Prompt") = adPromptAlwaysoConn.Open "Provider=SQLNCLI10;Server=myServerAddress;DataBase=myDataBase;Encrypt data sent over networkProvider=SQLNCLI10;Server=myServerAddress;Database=myDataBase;Trusted_Connection=yes;Encrypt=yes;SQL Native Client 9.0 OLE DB providerType: OLE DB ProviderUsage:Provider=SQLNCLIManufacturer: MicrosoftMore info about this provider »Customize stringexample values »Standard securityNote that the SQL Server Native Client OLE DB Provider does not support SQL Server 7.0. Provider=SQLNCLI;Server=myServerAddress;Database=myDataBase;Uid=myUsername; Pwd=myPassword;Trusted connectionProvider=SQLNCLI;Server=myServerAddress;Database=myDataBase;Trusted_Connection=yes;Equivalent key-value pair: "Integrated Security=SSPI" equals "Trusted_Connection=yes"Connecting to an SQL Server instanceThe syntax of specifying the server instance in the value of the server key is the same for all connection strings for SQL Server.Provider=SQLNCLI;Server=myServerName\theInstanceName;Database=myDataBase; Trusted_Connection=yes;Prompt for username and passwordThis one is a bit tricky. First you need to set the connection object's Prompt property to adPromptAlways. Then use the connection string to connect to the database.oConn.Properties("Prompt") = adPromptAlwaysoConn.Open "Provider=SQLNCLI;Server=myServerAddress;DataBase=myDataBase;Encrypt data sent over networkProvider=SQLNCLI;Server=myServerAddress;Database=myDataBase;Trusted_Connection=yes;Encrypt=yes;SQL Server Native Client 10.0 ODBC DriverType: ODBC DriverUsage:Driver={SQL Server Native Client 10.0}Manufacturer: MicrosoftMore info about this driver »Customize stringexample values »Standard securityDriver={SQL Server Native Client10.0};Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPasswo rd;Trusted ConnectionDriver={SQL Server Native Client10.0};Server=myServerAddress;Database=myDataBase;Trusted_Connection=yes; Equivalent key-value pair: "Integrated Security=SSPI" equals "Trusted_Connection=yes"Connecting to an SQL Server instanceThe syntax of specifying the server instance in the value of the server key is the same for all connection strings for SQL Server.Driver={SQL Server Native Client 10.0};Server=myServerName\theInstanceName; Database=myDataBase;Trusted_Connection=yes;Prompt for username and passwordThis one is a bit tricky. First you need to set the connection object's Prompt property to adPromptAlways. Then use the connection string to connect to the database.oConn.Properties("Prompt") = adPromptAlwaysDriver={SQL Server Native Client10.0};Server=myServerAddress;Database=myDataBase;Encrypt data sent over networkDriver={SQL Server Native Client10.0};Server=myServerAddress;Database=myDataBase;Trusted_Connection=yes;Encrypt=yes;SQL Native Client 9.0 ODBC DriverType: ODBC DriverUsage:Driver={SQL Native Client}Manufacturer: MicrosoftMore info about this driver »Customize stringexample values »Standard securityDriver={SQL Native Client};Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;Trusted ConnectionDriver={SQL Native Client};Server=myServerAddress;Database=myDataBase; Trusted_Connection=yes;Equivalent key-value pair: "Integrated Security=SSPI" equals "Trusted_Connection=yes"Connecting to an SQL Server instanceThe syntax of specifying the server instance in the value of the server key is the same for all connection strings for SQL Server.Driver={SQL NativeClient};Server=myServerName\theInstanceName;Database=myDataBase;Trusted_Connection=yes;Prompt for username and passwordThis one is a bit tricky. First you need to set the connection object's Prompt property to adPromptAlways. Then use the connection string to connect to the database.oConn.Properties("Prompt") = adPromptAlwaysDriver={SQL Native Client};Server=myServerAddress;Database=myDataBase;Customize stringexample values »MSDataShapeProvider=MSDataShape;Data Provider=SQLOLEDB;DataSource=myServerAddress;Initial Catalog=myDataBase;UserID=myUsername;Password=myPassword;【MYSQL】StandardServer=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword; Default port is 3306.Specifying portServer=myServerAddress;Port=1234;Database=myDataBase;Uid=myUsername;Pwd=myPa ssword;Download the driver at MySQL Developer ZoneNamed pipesServer=myServerAddress;Port=-1;Database=myDataBase;Uid=myUsername;Pwd=myPass word;It is the port value of -1 that tells the driver to use named pipes network protocol. This is available on Windows only. The value is ignored if Unix socket is used.Multiple serversUse this to connect to a server in a replicated server configuration without concern on which server to use.Server=serverAddress1 & serverAddress2 &etc..;Database=myDataBase;Uid=myUsername;Pwd=myPassword;Using encryptionThis one activates SSL encryption for all data sent between the client and server. The server needs to have a certificate installed.Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;Enc ryption=true;This option is available from Connector/NET version 5.0.3. In earlier versions, this option has no effect.Using encryption, alternativeSome reported problems with the above one. Try replacing the key "Encryption" with "Encrypt" instead.Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;Enc rypt=true;Specifying default command timeoutUse this one to specify a default command timeout for the connection. Please note that the property in the connection string does not supercede the individual command timeout property on an individual command object.Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;def ault command timeout=20;This option is available from Connector/NET version 5.1.4.Specifying connection attempt timeoutUse this one to specify the length in seconds to wait for a server connection before terminating the attempt and receive an error.Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;Con nection Timeout=5;Inactivating prepared statementsUse this one to instruct the provider to ignore any command prepare statements and prevent corruption issues with server side prepared statements.Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;Ign ore Prepare=true;The option was added in Connector/NET version 5.0.3 and Connector/NET version 1.0.9.Specifying portUse this one to specify what port to use for the connection.Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;Por t=3306;The port 3306 is the default MySql port.The value is ignored if Unix socket is used.Specifying network protocolUse this one to specify which network protocol to use for the connection.Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword; Protocol=socket;"socket" is the default value used if the key isn't specified. Value "tcp" is an equivalent for "socket".Manufacturer: MySQLMore info about this driver »Customize stringexample values »Local databaseDriver={MySQL ODBC 3.51 Driver};Server=localhost;Database=myDataBase;User=myUsername;Password=myPassword;Option=3;Remote databaseDriver={MySQL ODBC 3.51Driver};Server=myServerAddress;Database=myDataBase;User=myUsername;Password=myPassword;Option=3;Specifying TCP/IP portDriver={MySQL ODBC 3.51Driver};Server=myServerAddress;Port=3306;Database=myDataBase;User=myUsername; Password=myPassword;Option=3;The driver defaults to port value 3306, if not specified in the connection string, as 3306 is the default port for MySQL.Specifying character setDriver={MySQL ODBC 3.51Driver};Server=myServerAddress;charset=UTF8;Database=myDataBase;User=myUsern ame; Password=myPassword;Option=3;Note that the charset option works from version 3.51.17 of the driver.Specifying socketThis one specifies the Unix socket file or Windows named pipe to connect to. Used only for local client connections.Driver={MySQL ODBC 3.51Driver};Server=myServerAddress;Database=myDataBase;User=myUsername;Password=myPassword;Socket=MySQL;Option=3;On Windows, the socket variable is the name of the named pipe that is used for local client connections. The default value is MySQL.On Unix platforms, the socket variable is the name of the socket file that is used for local client connections. The default is /tmp/mysql.sock.Using SSLDriver={MySQL ODBC 3.51Driver};Server=myServerAddress;Database=myDataBase;User=myUsername;Password=myPassword;sslca=c:\cacert.pem;sslcert=c:\client-cert.pem;sslkey=c: \client-key.pem;sslverify=1;Option=3;SSLCA specifies the path to a file with a list of trust SSL CAsSSLCERT specifies the name of the SSL certificate file to use for establishing a secure connection.SSLKEY specifies the name of the SSL key file to use for establishing a secure connection. MySQL Connector/ODBC 5.1Type: ODBC DriverUsage:Driver={MySQL ODBC 5.1 Driver}Manufacturer: MySQLMore info about this driver »Customize stringexample values »Local databaseDriver={MySQL ODBC 5.1 Driver};Server=localhost;Database=myDataBase;User=myUsername;Password=myPassword;Option=3;Remote databaseDriver={MySQL ODBC 5.1Driver};Server=myServerAddress;Database=myDataBase;User=myUsername;Password=myPassword;Option=3;Specifying TCP/IP portDriver={MySQL ODBC 5.1Driver};Server=myServerAddress;Port=3306;Database=myDataBase;User=myUsername; Password=myPassword;Option=3;The driver defaults to port value 3306, if not specified in the connection string, as 3306 is the default port for MySQL.Specifying character setDriver={MySQL ODBC 5.1Driver};Server=myServerAddress;charset=UTF8;Database=myDataBase;User=myUsern ame; Password=myPassword;Option=3;Specifying socketThis one specifies the Unix socket file or Windows named pipe to connect to. Used only for local client connections.Driver={MySQL ODBC 5.1Driver};Server=myServerAddress;Database=myDataBase;User=myUsername;Password=myPassword;Socket=MySQL;Option=3;On Windows, the socket variable is the name of the named pipe that is used for local client connections. The default value is MySQL.On Unix platforms, the socket variable is the name of the socket file that is used for local client connections. The default is /tmp/mysql.sock.Using SSLDriver={MySQL ODBC 5.1Driver};Server=myServerAddress;Database=myDataBase;User=myUsername;Password=myPassword;sslca=c:\cacert.pem;sslcert=c:\client-cert.pem;sslkey=c: \client-key.pem;sslverify=1;Option=3;SSLCA specifies the path to a file with a list of trust SSL CAsSSLCERT specifies the name of the SSL certificate file to use for establishing a secure connection.SSLKEY specifies the name of the SSL key file to use for establishing a secure connection..NET Framework Data Provider for ODBCType: .NET Framework Wrapper Class LibraryUsage:System.Data.Odbc.OdbcConnectionManufacturer: MicrosoftMore info about this wrapper class library »Customize stringexample values »Bridging to MySQL Connector/ODBC 5.1This is just one connection string sample for the wrapping OdbcConnection class that calls the underlying ODBC Driver. See respective ODBC driver for more connection strings to use with this class.Driver={MySQL ODBC 5.1 Driver};Server=localhost;Database=myDataBase;User=myUsername;Password=myPassword;Option=3;。

数据库连接符号

数据库连接符号

数据库连接符号数据库连接符号是在数据库中连接两个或多个表格的一种结构或符号语法。

它们用于实现关系型数据库的关联操作,允许用户以各种方式检索和操作数据。

在这篇文章中,我们将讨论一些常见的数据库连接符号,并提供一些相关的参考内容。

1. 内连接符号(INNER JOIN):内连接是最常用的连接类型之一。

它基于两个表之间的匹配条件创建一个新表。

INNER JOIN 关键字将从两个表中选择满足匹配条件的行。

示例语法:```SELECT * FROM 表1 INNER JOIN 表2 ON 表1.列 = 表2.列;```在这个示例中,INNER JOIN 将根据两个表中的匹配条件(列)连接表1和表2,并返回满足条件的行。

2. 左连接符号(LEFT JOIN):左连接也是一种常见的连接类型。

它将返回左表中所有的行,以及右表中满足连接条件的行。

示例语法:```SELECT * FROM 表1 LEFT JOIN 表2 ON 表1.列 = 表2.列;```在这个示例中,LEFT JOIN 将返回表1中的所有行,以及与表1中的行匹配的表2中的行。

3. 右连接符号(RIGHT JOIN):右连接与左连接类似,只是返回右表中满足连接条件的行,以及左表中的所有行。

示例语法:```SELECT * FROM 表1 RIGHT JOIN 表2 ON 表1.列 = 表2.列;```在这个示例中,RIGHT JOIN 将返回表2中的所有行,以及与表2中的行匹配的表1中的行。

4. 全连接符号(FULL JOIN):全连接返回连接表中的所有行,不论是否满足连接条件。

示例语法:```SELECT * FROM 表1 FULL JOIN 表2 ON 表1.列 = 表2.列;```在这个示例中,FULL JOIN 将返回表1和表2中的所有行,并根据连接条件对它们进行匹配。

5. 交叉连接符号(CROSS JOIN):交叉连接返回两个表的笛卡尔积,即两个表的所有行组合。

MySQL中的连接字符串和连接选项配置

MySQL中的连接字符串和连接选项配置

MySQL中的连接字符串和连接选项配置在数据库应用程序中,连接到数据库是一个重要的步骤,连接字符串和连接选项配置是实现这一步骤的关键。

MySQL作为一种流行的关系型数据库管理系统(RDBMS),提供了丰富的连接字符串和连接选项配置功能,使得开发人员能够更好地控制和管理数据库连接。

连接字符串是用于指定数据库连接的字符串参数,包括数据库的地址、端口号、用户名、密码等信息。

连接选项配置是一组用于优化和调整数据库连接行为的参数,包括连接池大小、读写超时时间、字符编码等设置。

本文将详细介绍MySQL中连接字符串和连接选项配置的相关知识,希望能够帮助读者更好地理解和应用。

一、连接字符串连接字符串是用于指定数据库连接的字符串参数,它可以根据实际需求来设置不同的参数,以满足不同的数据库连接使用场景。

常见的连接字符串包括以下几个部分:1. 数据库地址数据库地址是指数据库服务器的地址和端口号,格式为"host:port"。

例如,localhost:3306表示连接到本地MySQL服务器的默认端口。

2. 用户名和密码用户名和密码是用于数据库身份验证的凭据,格式为"username:password"。

例如,root:123456表示使用用户名root和密码123456进行身份验证。

3. 数据库名称数据库名称是指要连接的数据库的名称,格式为"dbname"。

例如,mydatabase表示连接到名为mydatabase的数据库。

4. 字符编码字符编码是指数据库中存储的字符数据的编码格式,常用的编码格式包括UTF-8、GBK等。

可以通过设置字符编码来确保数据的正确存储和读取。

5. 其他可选参数除了上述基本参数外,连接字符串还可以包含其他可选参数,用于进一步优化和调整数据库连接行为。

例如,可以设置连接超时时间、读写超时时间、连接池大小等参数。

二、连接选项配置连接选项配置是一组用于优化和调整数据库连接行为的参数,可以通过连接字符串的方式进行配置。

数据库连接字串大全.

数据库连接字串大全.

数据库连接字串大全.· ODBCo 标准连接(Standard Security):"Driver={SQLServer};Server=Aron1;Database=pubs;Uid=sa;Pwd=asdasd;"1)当服务器为本地时Server可以使用(local);"Driver={SQLServer};Server=(local);Database=pubs;Uid=sa;Pwd=asdasd;"2)当连接远程服务器时,需指定地址、端口号和网络库"Driver={SQLServer};Server=130.120.110.001;Address=130.120.110.001,1052; Network=dbmssocn;Database=pubs;Uid=sa;Pwd=asdasd;"注:Address参数必须为IP地址,而且必须包括端口号o 信任连接(Trusted connection): (Microsoft Windows NT 集成了安全性)"Driver={SQLServer};Server=Aron1;Database=pubs;Trusted_Connection=yes;"或者"Driver={SQL Server};Server=Aron1;Database=pubs; Uid=;Pwd=;"o 连接时弹出输入用户名和口令对话框:Conn.Properties("Prompt") = adPromptAlwaysConn.Open "Driver={SQL Server};Server=Aron1;DataBase=pubs;"· OLE DB, OleDbConnection (.NET)o 标准连接(Standard Security):"Provider=sqloledb;Data Source=Aron1;Initial Catalog=pubs;Usero 信任连接(Trusted connection):"Provider=sqloledb;Data Source=Aron1;Initial Catalog=pubs;Integrated Security=SSPI;"(如果连接一个具体的已命名SQLServer实例,使用Data Source=Servere Name/Instance Name;但仅适用于SQLServer2000)例如:”Provider=sqloledb;Data Source=MyServerName/MyInstanceName;InitialCatalog=MyDatabaseName;User 连接时弹出输入用户名和口令对话框:Conn.Provider = "sqloledb"Conn.Properties("Prompt") = adPromptAlwaysConn.Open "Data Source=Aron1;Initial Catalog=pubs;"o 通过IP地址连接:"Provider=sqloledb;DataSource=190.190.200.100,1433;NetworkLibrary=DBMSSOCN;Initial Catalog=pubs;User(DBMSSOCN=TCP/IP代替Named Pipes, Data Source的末尾是需要使用的端口号(缺省为1433))· SqlConnection (.NET)o 标准连接(Standard Security):"Data Source=Aron1;Initial Catalog=pubs;User或者"Server=Aron1;Database=pubs;User(这两个连接串的结果相同)o 信任连接(Trusted connection):"Data Source=Aron1;Initial Catalog=pubs;Integrated Security=SSPI;"或者"Server=Aron1;Database=pubs;Trusted_Connection=True;"(这两个连接串的结果相同)(可以用serverName/instanceName代替Data Source,取值为一个具体的SQLServer实例,但仅适用于 SQLServer2000) o 通过IP地址连接:"Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial Catalog=pubs;User(DBMSSOCN=TCP/IP代替Named Pipes, Data Source的末尾是需要使用的端口号(缺省为1433))o SqlConnection连接的声明:C#:using System.Data.SqlClient;SqlConnection SQLConn = new SqlConnection();SQLConn.ConnectionString="my connectionstring";SQLConn.Open();:Imports System.Data.SqlClientDim SQLConn As SqlConnection = New SqlConnection()SQLConn.ConnectionString="my connectionstring"SQLConn.Open()· Data Shapeo MS Data Shape"Provider=MSDataShape;Data Provider=SQLOLEDB;Data Source=Aron1;Initial Catalog=pubs;User· 更多o 如何定义使用哪个协议§ 举例:"Provider=sqloledb;DataSource=190.190.200.100,1433;NetworkLibrary=DBMSSOCN;Initial Catalog=pubs;User名称网络协议库dbnmpntw Win32 Named Pipesdbmssocn Win32 Winsock TCP/IPdbmsspxn Win32 SPX/IPXdbmsvinn Win32 Banyan Vinesdbmsrpcn Win32 Multi-Protocol (Windows RPC)§ 重要提示当通过SQLOLEDB提供者进行连接时使用以下语法:Network Library=dbmssocn但通过MSDASQL提供者进行连接时使用以下语法:Network=dbmssocno 所有SqlConnection连接串属性§ 下表显示了 SqlConnection对象的所有连接串属性. 其中大多数的属性也在ADO中使用.所有属性和描述来自于msdn.名称缺省值描述Application Name 应用程序名称或者当没有提供应用程序时为.Net SqlClient数据提供者AttachDBFilename或者extended properties或者Initial File Name 主要文件的名字,包括相关联数据库的全路径。

Oracle数据库连接字符串

Oracle数据库连接字符串

Oracle数据库连接字符串(经典大全)2009-08-21 14:36ODBC新版本Driver={Microsoft ODBC for Oracle};Server=myServerAddress;Uid=myUsername;Pwd=myPassword;旧版本Driver={Microsoft ODBC Driver for Oracle};ConnectString=OracleServer.world;Uid=myUsername;Pwd=myPassword; OLE DB, OleDbConnection (.NET)标准连接此连接字符串适用了微软的驱动。

Provider=msdaora;Data Source=MyOracleDB;User Id=myUsername;Password=myPassword;受信连接Provider=msdaora;Data Source=MyOracleDB;Persist Security Info=False;Integrated Security=Yes;标准连接由Oracle提供的驱动。

Provider=OraOLEDB.Oracle;Data Source=MyOracleDB;User Id=myUsername;Password=myPassword;受信连接Provider=OraOLEDB.Oracle;Data Source=MyOracleDB;OSAuthent=1;Oracle.DataAccess.Client.OracleConnectionData Source=TORCL;User Id=myUsername;Password=myPassword;标准安全连接Data Source=TORCL;Integrated Security=SSPI;使用而不使用tnsnames.oraDataSource=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=MyHost)(PORT=MyPort)))(C ONNECT_DATA=(SERVER=DEDICA TED)(SERVICE_NAME=MyOracleSID)));UserId=myUsername;Password=myPassword;OracleConnection, Oracle Data Provider, , System.Data.OracleClient.OracleConnection标准Data Source=MyOracleDB;Integrated Security=yes;用于8i RC3及以后的版本指定用户名和密码Data Source=MyOracleDB;User Id=myUsername;Password=myPassword;Integrated Security=no;用于8i RC3及以后的版本忽略tnsnames.ora另一种不需要使用DSN的连接方式。

C#数据库连接字符串

C#数据库连接字符串

C#数据库连接字符串⽂章转载⾄:sa登陆:"Data Source=.;Initial Catalog=数据库;User ID=sa,pwd=;";windows登陆Data Source=.;Initial Catalog=数据库;Integrated Security=Truec#数据库连接字符串集合(⼀)常⽤连接:1.使⽤SqlConnection对象:a. Sql 验证public void SqlConnectionOpen(){SqlConnection conn= new SqlConnection();conn.ConnectionString = "user id=sa;password=;initial catalog=northwind;datasource=localhost;connect Timeout=20";conn.Open();}b. Windows ⾝份验证public void SqlConnectionOpen(){SqlConnection conn= new SqlConnection();conn.ConnectionString = "Integrated Security=SSPI;initial catalog=northwind;datasource=localhost;connect Timeout=20";conn.Open();}2.使⽤OleDbConnection对象:public void OleDBConnectionOpen(){OleDBConnection conn = new OleDbconnection();conn.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;DataSource=C:\Customer.mdb";conn.Open();}(⼆)其它:1.ODBC连接Access本地数据库conGoodDay.Open("Driver={Microsoft Access Driver(*.mdb)};"+"Dbq=C:\a.mdb;"+"Uid=Admin;"+"Pwd=;");2.ODBC连接Access系统数据库conGoodDay.Open("Driver={Microsoft Access Driver(*.mdb)};"+"Dbq=C:\a.mdb;"+"SystemDB=Admin;"+"Pwd=;");3.ODBC连接Access系统数据库conGoodDay.Open("Driver={Microsoft Access Driver(*.mdb)};"+"Dbq=\\server\share\a.mdb;");4.ODBC连接Excel系统数据库conGoodDay.Open("Driver={Microsoft Access Driver(*.xls)};"+"DriverId=790;"+"Dbq=C:\a.xls;"+"DefaultDir=c:\somepath;");5.ODBC连接Oracle系统数据库conGoodDay.Open("Driver={Microsoft ODBC for oracle};"+"Server=OracleServer.world;"+"Uid=Admin;"+"Pwd=password;");6.ODBC连接Sql ServrconGoodDay.Open("Driver={Sql Server};"+"Server=myServer;"+"Database=myDatabaseName;""Uid=Admin;"+"Pwd=password;");7.ODBC连接Visual FoxProconGoodDay.Open("Driver={Microsoft Visual FoxPro Driver};"+"SourceType=DBC;"+"SourceDB=c:a.dbc;"+"Exclusive=No;");Windows ⾝份验证建议使⽤ Windows ⾝份验证(有时也称为“集成安全性”)连接到⽀持其的数据源。

sql server 2008数据库连接字符串大全

sql server 2008数据库连接字符串大全

一、.NET Framework Data Provider for SQL Server类型:.NET Framework类库使用:System.Data.SqlClient.SqlConnection厂商:Microsoft1.标准安全连接复制代码代码如下:Data Source = myServerAddress;Initial Catalog = myDataBase;User Id = myUsername;Password = myPassword;使用服务器名\实例名作为连接指定SQL Server实例的数据源。

如果你使用的是SQL Server 2008 Express版,实例名为SQLEXPRESS。

2.可替代的标准安全连接复制代码代码如下:Server = myServerAddress;Database = myDataBase;User ID = myUsername;Password = myPassword;Trusted_Connection = False;这条连接字符串跟上一条效果一样。

把这条写出来只是想说,其实很多连接字符串的关键字有多种写法。

3.信任连接复制代码代码如下:Data Source = myServerAddress;Initial Catalog = myDataBase;Integrated Security = SSPI;可替代的信任连接复制代码代码如下:Server = myServerAddress;Database = myDataBase;Trusted_Connection = True;4.连接Windows CE设备的信任连接通常一台Windows CE设备在一个域里是不能被认证和登录的。

为了让一台CE设备使用SSPI或信任连接和认证,可以使用下面的连接字符串:复制代码代码如下:Data Source = myServerAddress;Initial Catalog = myDataBase;Integrated Security = SSPI;User ID = myDomain\myUsername;Password = myPassword;说明一下,这条语句只能在CE设备上用。

JDBC—数据库的连接字符串及连接方法(各类数据库)

JDBC—数据库的连接字符串及连接方法(各类数据库)

JDBC数据库连接字符串及连接方法1、连接mysql第一步:从mysql-connector-java目录下面将mysql-connector的jar包导入到lomboz_eclipse中第二步:Class.forName("com.mysql.jdbc.Driver");Connection conn=DriverManager.getConnection("jdbc:mysql://localhost/mydata?"+"user=root&password=root"); 注:“?”前的“mydata”是具体的数据库名称,根据需要连接的具体数据库名称填入。

2、Oracle8/8i/9i数据库(thin模式)第一步:将Oracle提供的jar包导入到编程环境中(如lomboz_eclipse)。

第二步:Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();Connection conn= DriverManager.getConnection(url, user, password);url="jdbc:oracle:thin:@localhost:1521:orcl"; //orcl为数据库的SIDuser="test";password="test";3、连接SQLServer2005Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");conn = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=mydata","sa","root"); stmt = conn.createStatement();rs = stmt.executeQuery("select * from users");while(rs.next()) {System.out.println(rs.getString(2));}4、连接access首先建立数据库和数据源lxhdb,当数据库没密码时:Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");conn = DriverManager.getConnection("jdbc:odbc:lxhdb");如果有密码conn = DriverManager.getConnection("jdbc:odbc:数据源","用户名","密码");stmt = conn.createStatement();rs = stmt.executeQuery("select * from user");5、SQL Server7.0/2000数据库Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=mydb";//mydb为数据库String user="sa";String password="";Connection conn= DriverManager.getConnection(url,user,password);6、DB2数据库Class.forName("com.ibm.db2.jdbc.app.DB2Driver ").newInstance();String url="jdbc:db2://localhost:5000/sample"; //sample为你的数据库名String user="admin";String password="";Connection conn= DriverManager.getConnection(url,user,password);7、Sybase数据库Class.forName("com.sybase.jdbc.SybDriver").newInstance();String url =" jdbc:sybase:Tds:localhost:5007/myDB";//myDB为你的数据库名Properties sysProps = System.getProperties();SysProps.put("user","userid");SysProps.put("password","user_password");Connection conn= DriverManager.getConnection(url, SysProps);8、Informix数据库Class.forName("rmix.jdbc.IfxDriver").newInstance();String url = "jdbc:informix-sqli://123.45.67.89:1533/myDB:INFORMIXSERVER=myserver; user=testuser;password=testpassword"; //myDB为数据库名Connection conn= DriverManager.getConnection(url);9、PostgreSQL数据库Class.forName("org.postgresql.Driver").newInstance();String url ="jdbc:postgresql://localhost/myDB" //myDB为数据库名String user="myuser";String password="mypassword";Connection conn= DriverManager.getConnection(url,user,password);10、连接excel数据源(ODBC)点击添加,在弹出窗口中选择“Driver do Microsoft Excel(*.xls)”名为myxls Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");conn = DriverManager.getConnection("jdbc:odbc:myxls");stmt = conn.createStatement();rs = stmt.executeQuery("select * from [Sheet1$]");。

MYSQL连接字符串参数详细解析(大全参考)

MYSQL连接字符串参数详细解析(大全参考)

MYSQL连接字符串参数详细解析(⼤全参考)Connector/Net Connection String Options ReferenceDatabase=dbname;Data Source=192.168.1.1;Port=3306;User Id=root;Password=****;Charset=utf8;TreatTinyAsBoolean=false;顺便把源码中涉及的所有属性都列出来:Server,host, data source, datasource, address, addr, network address: 数据库位置(以上任何关键字均可)Database,initial catalog:数据库名Port: socket 端⼝,默认 3306ConnectionProtocol,protocol:连接协议,默认 SocketsPipeName,pipe:连接管道,默认 MYSQLUseCompression,compress:连接是否压缩,默认 falseAllowBatch:是否允许⼀次执⾏多条SQL语句,默认 trueLogging:是否启⽤⽇志,默认 falseSharedMemoryName:内存共享的名称,默认 MYSQLUseOldSyntax,old syntax, oldsyntax:是否兼容旧版的语法,默认 falseConnectionTimeout,connection timeout:连接超时等待时间,默认15sDefaultCommandTimeout,command timeout:MySqlCommand 超时时间,默认 30sUserID, uid, username, user name, user:数据库登录帐号Password,pwd:登录密码PersistSecurityInfo:是否保持敏感信息,默认 falseEncrypt:已经⽤ SSL 替代了,默认 falseCertificateFile:证书⽂件(.pfx)格式CertificatePassword:证书的密码CertificateStoreLocation:证书的存储位置CertificateThumbprint:证书指纹AllowZeroDateTime:⽇期时间能否为零,默认 falseConvertZeroDateTime:为零的⽇期时间是否转化为 DateTime.MinValue,默认 falseUseUsageAdvisor, usage advisor:是否启⽤助⼿,会影响数据库性能,默认 falseProcedureCacheSize,procedure cache, procedurecache:同⼀时间能缓存⼏条存储过程,0为禁⽌,默认 25 UsePerformanceMonitor,userperfmon, perfmon:是否启⽤性能监视,默认 falseIgnorePrepare:是否忽略 Prepare() 调⽤,默认 trueUseProcedureBodies,procedure bodies:是否检查存储过程体、参数的有效性,默认 trueAutoEnlist:是否⾃动使⽤活动的连接,默认 trueRespectBinaryFlags:是否响应列上元数据的⼆进制标志,默认 trueTreatTinyAsBoolean:是否将 TINYINT(1) 列视为布尔型,默认 trueAllowUserVariables:是否允许 SQL 中出现⽤户变量,默认 falseInteractiveSession,interactive:会话是否允许交互,默认 falseFunctionsReturnString:所有服务器函数是否按返回字符串处理,默认 falseUseAffectedRows:是否⽤受影响的⾏数替代查找到的⾏数来返回数据,默认 falseOldGuids:是否将 binary(16) 列作为 Guids,默认 falseKeepalive:保持 TCP 连接的秒数,默认0,不保持。

ado的连接字符串

ado的连接字符串

ado的连接字符串在 ADO(ActiveX Data Objects)中,连接字符串是用于指定与数据库建立连接的字符串。

它包含了连接数据库所需的各种参数,如数据库类型、服务器名称、用户名、密码、数据库名称等。

以下是一个示例的 ADO 连接字符串,用于连接 SQL Server 数据库:```sql"Provider=SQLOLEDB;Data Source=your-server-name;Initial Catalog=your-database-name;User ID=your-username;Password=your-password;"```在这个示例中,你需要替换以下内容:- `Provider`:指定数据库提供程序。

对于 SQL Server,通常使用`SQLOLEDB`。

- `Data Source`:数据库服务器的名称或 IP 地址。

- `Initial Catalog`:要连接的数据库名称。

- `User ID`:用于连接数据库的用户名。

- `Password`:用户的密码。

请注意,上述示例仅为连接 SQL Server 数据库的基本连接字符串。

根据你实际使用的数据库类型和配置,连接字符串的参数可能会有所不同。

你还可以根据需要添加其他参数,例如连接超时、字符集等。

如果你使用的是其他类型的数据库(如 MySQL、Oracle、Access 等),连接字符串的格式和参数将有所不同。

你需要根据具体的数据库类型和要求来构建相应的连接字符串。

此外,还可以使用连接字符串生成工具或查看数据库提供商的文档来获取更详细和准确的连接字符串信息。

SQL数据库连接字符串的几种写法整理

SQL数据库连接字符串的几种写法整理

SQL数据库连接字符串的⼏种写法整理⼀、远程连接1.sql server ⾝份验证连接字符串:private string ConnstrSqlServer = "server=服务器名称;uid=登录名称;pwd=登录密码;database=数据库名称";2.windows ⾝份验证连接字符串:private string ConnstrWindows = "server=服务器名称;database=数据库名称;Trusted_Connection=SSPI";⼆、本地连接. 在 C# 代码中⽤SqlClient的⽅式访问 SQL Server 2008-2014 数据库 Framework Data Provider for SQL Server 标准写法 Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;2. .NET Framework Data Provider for SQL Server 另⼀种标准写法 Server=myServerAddress;Database=myDataBase;User ID=myUsername;Password=myPassword;Trusted_Connection=False; Framework Data Provider for SQL Server 信任连接写法 Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI; Framework Data Provider for SQL Server 信任连接另⼀种写法 Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;。

OLE DB各种数据库连接字符串

OLE DB各种数据库连接字符串
SQL Server 使用 OLE DB 所设置的连接字符串:
标准连接方式
Provider=sqloledb;Data Source=datasource;Initial Catalog=DbName;User Id=username;Password=pwd;
信任连接方式:
Provider=sqloledb;Data Source=datasource;Initial Catalog=DbName;Integrated Security=true;
Excel 使用 OLE DB 所设置的连接字符串
标准连接方式:
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/MyEcxel.xls;Extended Properties=" ";
------------------------------------------------------------------------------------------
Informix 使用 OLE DB 所设置的连接字符串
IBM Informix OLE DB Provider:
Provider=Ifxoledbc.2;User ID=username;Password=PWD;Data Source=dbName@serverName;Persist Security Info=true;
Oracle 使用 OLE DB 所设置的连接字符串:
微软提供的标准安全连接方式:
Provider=msdaora;Data Source=datasource;User Id=username;Password=PWD;

java连接Mysql的连接字符串怎么写的

java连接Mysql的连接字符串怎么写的
SysProps.put("password","user_password");
Connection conn= DriverManager.getConnection(url, SysProps);
5、Informix数据库
Class.forName("rmix.jdbc.IfxDriver").newInstance();
Connection conn = DriverManager.getConnection(url,"","");
Statement stmtNew=conn.createStatement() ;
6、MySQL数据库
Class.forName("com.mysql.jdbc.Driver");
String url ="jdbc:mysql://localhost/myDB;
//myDB为数据库名
String user="root";
String password="root";
String url = "jdbc:informix-sqli://123.45.67.89:1533/myDB:INFORMIXSERVER=myserver;
user=testuser;password=testpassword"; //myDB为数据库名
Connection conn= DriverManager.getConnection(url);
String user="test";
String password="test";

(C#)SQLite数据库连接字符串

(C#)SQLite数据库连接字符串

(C#)SQLite数据库连接字符串最常⽤的:Data Source=filename;Version=3;⾃增主键:Create test1([id] integer PRIMARY KEY AUTOINCREMENT,[name]);Basic(基本的)Data Source=filename;Version=3;Using UTF16(使⽤UTF16编码)Data Source=filename;Version=3;UseUTF16Encoding=True;With password(带密码的)Data Source=filename;Version=3;Password=myPassword;Using the pre 3.3x database format(使⽤3.3x前数据库格式)Data Source=filename;Version=3;Legacy Format=True;Read only connection(只读连接)Data Source=filename;Version=3;Read Only=True;With connection pooling(设置连接池)Data Source=filename;Version=3;Pooling=False;Max Pool Size=100;Using DateTime.Ticks as datetime format()Data Source=filename;Version=3;DateTimeFormat=Ticks;Store GUID as text(把Guid作为⽂本存储,默认是Binary)Data Source=filename;Version=3;BinaryGUID=False;如果把Guid作为⽂本存储需要更多的存储空间Specify cache size(指定Cache⼤⼩)Data Source=filename;Version=3;Cache Size=2000;Cache Size 单位是字节Specify page size(指定页⼤⼩)Data Source=filename;Version=3;Page Size=1024;Page Size 单位是字节Disable enlistment in distributed transactionsData Source=filename;Version=3;Enlist=N;Disable create database behaviour(禁⽤创建数据库⾏为)Data Source=filename;Version=3;FailIfMissing=True;默认情况下,如果数据库⽂件不存在,会⾃动创建⼀个新的,使⽤这个参数,将不会创建,⽽是抛出异常信息Limit the size of database(限制数据库⼤⼩)Data Source=filename;Version=3;Max Page Count=5000;The Max Page Count is measured in pages. This parameter limits the maximum number of pages of the database.Disable the Journal File (禁⽤⽇志回滚)Data Source=filename;Version=3;Journal Mode=Off;This one disables the rollback journal entirely.Persist the Journal File(持久)Data Source=filename;Version=3;Journal Mode=Persist;基本连接Sqlite数据库:Data Source=mydb.db;Version=3;--"Version" 的可能值: "2″指 SQLite 2.x (default);"3″指 SQLite 3.x 连接同时创建⼀个新的Sqlite数据库:Data Source=mydb.db;Version=3;New=True;启⽤压缩连接Sqlite数据库:Data Source=mydb.db;Version=3;Compress=True;指定连接Sqlite数据库的缓存⼤⼩:Data Source=mydb.db;Version=3;Cache Size=3000;。

mysql字符串sql_mysql中字符串拼接查询sql语句总结

mysql字符串sql_mysql中字符串拼接查询sql语句总结

mysql字符串sql_mysql中字符串拼接查询sql语句总

在MySQL中,字符串拼接可以使用CONCAT函数来实现。

下面是一些常用的字符串拼接查询语句总结:
1.将两个字段拼接成一个新的字符串:
SELECT CONCAT(field1, field2) AS new_string FROM table;
2.将字段和常量拼接成一个新的字符串:
SELECT CONCAT(field, ' constant') AS new_string FROM table;
3.将多个字段拼接成一个新的字符串:
SELECT CONCAT(field1, field2, field3) AS new_string FROM table;
4.将多个字段和常量拼接成一个新的字符串:
SELECT CONCAT(field1, field2, ' constant') AS new_string FROM table;
5.使用分隔符将多个字段拼接成一个新的字符串:
SELECT CONCAT_WS('-', field1, field2, field3) AS new_string FROM table;
需要注意的是,使用CONCAT函数时,字段或常量之间需要使用逗号进行分隔,而使用CONCAT_WS函数时,第一个参数是分隔符,后面的参数是要拼接的字段或常量。

另外,还可以使用+运算符来进行字符串拼接,例如:
SELECT field1 + field2 AS new_string FROM table;
但是需要注意的是,这种方式只适用于将两个字段拼接成一个新的字符串,并且字段类型必须是数字类型。

pgsql数据库连接串写法

pgsql数据库连接串写法

pgsql数据库连接串写法在使用PostgreSQL数据库时,可以使用以下几种方式来编写数据库连接串:1. 基本格式:host=<hostname> port=<port> dbname=<database>user=<username> password=<password>。

其中,`<hostname>`是数据库服务器的主机名或IP地址,`<port>`是数据库服务器监听的端口号(默认为5432),`<database>`是要连接的数据库名称,`<username>`和`<password>`是登录数据库所需的用户名和密码。

2. 使用连接字符串:postgresql://<username>:<password>@<hostname>:<port>/<datab ase>。

这是一种常见的连接字符串格式,其中`<username>`、`<password>`、`<hostname>`、`<port>`和`<database>`分别代表用户名、密码、主机名(或IP地址)、端口号和数据库名称。

3. 使用环境变量:export PGHOST=<hostname>。

export PGPORT=<port>。

export PGDATABASE=<database>。

export PGUSER=<username>。

export PGPASSWORD=<password>。

这种方式通过设置环境变量来指定连接参数,然后使用默认的连接串来连接数据库。

4. 高级选项:host=<hostname> port=<port> dbname=<database>user=<username> password=<password> sslmode=<mode>。

C# 连接SQL数据库 常用连接字符串

C# 连接SQL数据库 常用连接字符串

一:C# 连接SQL数据库Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword;Server=myServerAddress;Database=myDataBase;UserID=myUsername;Password=myPassword;Trusted_Connection=False;Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;Server=myServerName\theInstanceName;Database=myDataBase;Trusted_Connection=True;Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;1:Integrated Security参数当设置Integrated Security为True 的时候,连接语句前面的UserID, PW 是不起作用的,即采用windows身份验证模式。

只有设置为False 或省略该项的时候,才按照UserID, PW 来连接。

Integrated Security 还可以设置为:sspi ,相当于True,建议用这个代替True。

Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=true;Data Source=myServerAddress;Initial Catalog=myDataBase;;User ID=myUsername;Password=myPasswordIntegrated Security=false;2:参数Trusted_ConnectionTrusted_Connection=true,将使用当前的Windows 帐户凭据进行身份验证Trusted_Connection=false;将不采用信任连接方式(也即不采用Windows验证方式),而改由SQL Server 2000验证方式Server=myServerAddress;Database=myDataBase;User ID=myUsername;Password=myPassword;Trusted_Connection=false;Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;3:Initial Catalog是你要连接的数据库的名字4:WINCE连接Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;User ID=myDomain\myUsername;Password=myPassword;二:可以利用SqlConnectionStringBuilder,这样不必去记住名称。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

数据库连接字符串大全计算机编程交流群:60231207 一.SQL Server1.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};Server=Aron1;DataBase=pubs;"2.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 serverName\instanceName as Data Source to use an specifik SQLServer instance, only SQLServer2000)Prompt for username and password:oConn.Provider = "sqloledb"oConn.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 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))3. SqlConnection (.NET)Standard Security:"Data Source=Aron1;Initial Catalog=pubs;User Id=sa;Password=asdasd;"- or -"Server=Aron1;Database=pubs;User ID=sa;Password=asdasd;Trusted_Connection=False" (both 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;"(both connection strings produces the same result) (use serverName\instanceName as Data Source to use an specifik SQLServer instance, only 2009.05.19计算机编程交流群南昌大学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 Data Source is the port to use (1433 is the default))Declare the SqlConnection:C#:using System.Data.SqlClient;SqlConnection cnn = new SqlConnection();cnn.ConnectionString="my connection string";cnn.Open();:Imports System.Data.SqlClientDim oSQLConn As SqlConnection = New SqlConnection()oSQLConn.ConnectionString="my connection string"oSQLConn.Open()二.Data ShapeMS Data Shape"Provider=MSDataShape;Data Provider=SQLOLEDB;Data Source=Aron1;Initial Catalog=pubs;User ID=sa;Password=asdasd;"Want to learn data shaping? Check out 4GuyfFromRolla's great article about Data ShapingRead moreHow 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 librarydbnmpntw Win32 Named Pipesdbmssocn Win32 Winsock TCP/IPdbmsspxn Win32 SPX/IPXdbmsvinn Win32 Banyan Vinesdbmsrpcn 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=dbmssocnAll SqlConnection connection string propertiesThis table shows all connection string properties for the SqlConnection object. Most of the properties are also used in ADO. All properties and descriptions is from msdn.Name DefaultDescription Application NameThe name of the application, or '.Net SqlClient Data Provider' if no application name is provided. AttachDBFilename或extendedproperties 或Initial File NameThe 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或Connection Timeout 15 The length of time (in seconds) to wait for a connection 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 iscompared with the current time, and the connection isdestroyed if that time span (in seconds) exceeds the valuespecified by connection lifetime. Useful in clusteredconfigurations to force load balancing between a runningserver and a server just brought on-line.Connection Reset 'true' Determines whether the database connection is reset whenbeing removed from the pool. Setting to 'false' avoids makingan additional server round-trip when obtaining a connection,but the programmer must be aware that the connection state isnot being reset.Current Language The SQL Server Language record name.Data Source 或Server 或Address 或Addr或Network AddressThe name or network address of the instance of SQL Server towhich to connect. Enlist 'true' When true, the pooler automatically enlists the connection in the creation thread's current transaction context.Initial Catalog或DatabaseThe name of the database. Integrated Security或Trusted_Connection'false' Whether the connection is to be a secure connection or not. Recognized values are 'true', 'false', and 'sspi', which is equivalent to 'true'. Max Pool Size100 The maximum number of connections allowed in the pool. Min Pool Size 0 The minimum number of connections allowed in the pool.Network Library 或 Net 'dbmsso cn'The network library used to establish a connection to aninstance of SQL Server. Supported values include dbnmpntw(Named Pipes), dbmsrpcn (Multiprotocol), dbmsadsn (AppleTalk), dbmsgnet (VIA), dbmsipcn (Shared Memory) anddbmsspxn (IPX/SPX), and dbmssocn (TCP/IP). Thecorresponding network DLL must be installed on the system towhich you connect. If you do not specify 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或Pwd The password for the SQL Server account logging on.Persist Security Info'false' When set 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 SQLConnection object is drawn from theappropriate pool, or if necessary, is created and added to theappropriate pool.User ID The SQL Server login account.Workstation ID the local computer name The name of the workstation connecting to SQL Server.Note用“;”分隔每个属性。

相关文档
最新文档