当前位置:文档之家› SQL数据库连接字符串大全

SQL数据库连接字符串大全

SQL数据库连接字符串大全
SQL数据库连接字符串大全

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") = adPromptAlways

oConn.Open "Driver={SQL Server};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 serverName\instanceName as Data Source to use an specifik SQLServer instance, only SQLServer2000)

Prompt for username and password:

oConn.Provider = "sqloledb"

oConn.Properties("Prompt") = adPromptAlways

oConn.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))

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 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 oSQLConn = new SqlConnection();

oSQLConn.ConnectionString="my connection string";

oSQLConn.Open();

https://www.doczj.com/doc/4a7879646.html,:

Imports System.Data.SqlClient

Dim oSQLConn As SqlConnection = New SqlConnection()

oSQLConn.ConnectionString="my connection string"

oSQLConn.Open()

Data Shape

MS 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 Shaping >> Read more

How to define which network protocol to use

Example:

"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 Vines

dbmsrpcn Win32 Multi-Protocol (Windows RPC)

Important note!

When connecting through the SQLOLEDB provider use the syntax Network Library=dbmssocn and when connecting through MSDASQL provider use the syntax Network=dbmssocn

All SqlConnection connection string properties

This table shows all connection string properties for the https://www.doczj.com/doc/4a7879646.html, 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.

AttachDBFilename

-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 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 lifetime. 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 obtaining 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 thread's 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 are '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 SQL 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 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

-or-

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 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 than once, the value from the last one in the connection string will be used. If you are building your connection string in your app using values from user input fields, make sure the user can't change the connection string by inserting an additional property with another value within the user value.

SQL Server 2005

SQL Native Client ODBC Driver

Standard security:

"Driver={SQL Native Client};Server=Aron1;Database=pubs;UID=sa;PWD=asdasd;"

Trusted connection:

"Driver={SQL Native Client};Server=Aron1;Database=pubs;Trusted_Connection=yes;" Equivalents

Integrated Security=SSPI equals Trusted_Connection=yes

Prompt for username and password:

oConn.Properties("Prompt") = adPromptAlways

oConn.Open "Driver={SQL Native Client};Server=Aron1;DataBase=pubs;"

Enabling MARS (multiple active result sets):

"Driver={SQL Native Client};Server=Aron1;Database=pubs;Trusted_Connection=yes;MARS_Connection=yes" Equivalents

MultipleActiveResultSets=true equals MARS_Connection=yes

Using MARS with SQL Native Client, by Chris Lee >>

Encrypt data sent over network:

"Driver={SQL Native Client};Server=Aron1;Database=pubs;Trusted_Connection=yes;Encrypt=yes"

Attach a database file on connect to a local SQL Server Express instance:

"Driver={SQL Native Client};Server=.\SQLExpress;AttachDbFilename=c:\asd\qwe\mydbfile.mdf;Database=dbname;Tr usted_Connection=Yes;"

- or -

"Driver={SQL Native Client};Server=.\SQLExpress;AttachDbFilename=|DataDirectory|mydbfile.mdf;Database=dbnam e;Trusted_Connection=Yes;"

(use |DataDirectory| when your database file resides in the data directory)

Why is the "Database" parameter needed? Answer: If the database was previously attached, SQL Server does not reattach it (it uses the attached database as the default for the connection). Download the SQL Native Client here >> (the package contains booth the ODBC driver and the OLE DB provider)

Using SQL Server 2005 Express? Don't miss the server name syntax: SERVERNAME\SQLEXPRESS (Substitute "SERVERNAME" with the name of the computer) SQL Native Client OLE DB Provider

Standard security:

"Provider=SQLNCLI;Server=Aron1;Database=pubs;UID=sa;PWD=asdasd;"

Trusted connection:

"Provider=SQLNCLI;Server=Aron1;Database=pubs;Trusted_Connection=yes;"

Equivalents

Integrated Security=SSPI equals Trusted_Connection=yes

Prompt for username and password:

oConn.Properties("Prompt") = adPromptAlways

oConn.Open "Provider=SQLNCLI;Server=Aron1;DataBase=pubs;"

Enabling MARS (multiple active result sets):

"Provider=SQLNCLI;Server=Aron1;Database=pubs;Trusted_Connection=yes;MarsConn=yes" Equivalents

MarsConn=yes equals MultipleActiveResultSets=true equals MARS_Connection=yes

Using MARS with SQL Native Client, by Chris Lee >>

Encrypt data sent over network:

"Provider=SQLNCLI;Server=Aron1;Database=pubs;Trusted_Connection=yes;Encrypt=yes"

Attach a database file on connect to a local SQL Server Express instance:

"Provider=SQLNCLI;Server=.\SQLExpress;AttachDbFilename=c:\asd\qwe\mydbfile.mdf;Databa se=dbname;Trusted_Connection=Yes;"

- or -

"Provider=SQLNCLI;Server=.\SQLExpress;AttachDbFilename=|DataDirectory|mydbfile.mdf;Dat abase=dbname;Trusted_Connection=Yes;"

(use |DataDirectory| when your database file resides in the data directory)

Why is the "Database" parameter needed? Answer: If the database was previously attached, SQL Server does not reattach it (it uses the attached database as the default for the connection). Download the SQL Native Client here >> (the package contains booth the ODBC driver and the OLE DB provider)

Using SQL Server 2005 Express? Don't miss the server name syntax: SERVERNAME\SQLEXPRESS (Substitute "SERVERNAME" with the name of the computer) 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)

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))

Enabling MARS (multiple active result sets):

"Server=Aron1;Database=pubs;Trusted_Connection=True;MultipleActiveResultSets=true"

Note! Use https://www.doczj.com/doc/4a7879646.html, 2.0 for MARS functionality. MARS is not supported in https://www.doczj.com/doc/4a7879646.html, 1.0 nor https://www.doczj.com/doc/4a7879646.html, 1.1

Streamline your Data Connections by Moving to MARS, by Laurence Moroney, https://www.doczj.com/doc/4a7879646.html, >> Attach a database file on connect to a local SQL Server Express instance:

"Server=.\SQLExpress;AttachDbFilename=c:\asd\qwe\mydbfile.mdf;Database=dbname;Database =dbname;Trusted_Connection=Yes;"

- or -

"Server=.\SQLExpress;AttachDbFilename=|DataDirectory|mydbfile.mdf;Database=dbname;Trust ed_Connection=Yes;"

(use |DataDirectory| when your database file resides in the data directory)

Why is the "Database" parameter needed? Answer: If the database was previously attached, SQL Server does not reattach it (it uses the attached database as the default for the connection).

Using "User Instance" on a local SQL Server Express instance:

"Data Source=.\SQLExpress;integrated security=true;attachdbfilename=|DataDirectory|\mydb.mdf;user instance=true;"

The "User Instance" functionality creates a new SQL Server instance on the fly during connect. This works only on a local SQL Server 2005 instance and only when connecting using windows authentication over local named pipes. The purpose is to be able to create a full rights SQL Server instance to a user with limited administrative rights on the computer. To enable the functionality: sp_configure 'user instances enabled','1' (0 to disable)

Using SQL Server 2005 Express? Don't miss the server name syntax: SERVERNAME\SQLEXPRESS (Substitute "SERVERNAME" with the name of the computer) Context Connection - connecting to "self" from within your CLR stored prodedure/function

C#:

using(SqlConnection connection = new SqlConnection("context connection=true"))

{

connection.Open();

// Use the connection

}

Visual Basic:

Using connection as new SqlConnection("context connection=true")

connection.Open()

' Use the connection

End Using

The context connection lets you execute Transact-SQL statements in the same context (connection) that your code was invoked in the first place.

Read more

When to use SQL Native Client?

.Net applications

Do not use the SQL Native Client. Use the .NET Framework Data Provider for SQL Server

(SqlConnection).

COM applications, all other then .Net applications

Use the SQL Native Client if you are accessing an SQL Server 2005 and need the new features of SQL Server 2005 such as MARS, encryption, xml data type etc. Continue use your current provider (OLE DB / ODBC through the MDAC package) if you are not connecting to an SQL Server 2005 (that's quite obvious eh..) or if you are connecting to an SQL Server 2005 but are not using any of the new SQL Server 2005 features.

For more details on the differences between MDAC and SQL Native Client, read this msdn article >>

Access

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 DB, OleDbConnection (.NET)

Standard security:

"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\somepath\mydb.mdb;User Id=admin;Password=;"

Workgroup (system database):

"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\somepath\mydb.mdb;Jet OLEDB:System Database=system.mdw;"

With password:

"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\somepath\mydb.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;"

OLE DB, OleDbConnection (.NET)

Standard security:

"Provider=msdaora;Data Source=MyOracleDB;User Id=UserName;Password=asdasd;"

This one's from Microsoft, the following are from Oracle

Standard Security:

"Provider=OraOLEDB.Oracle;Data Source=MyOracleDB;User Id=Username;Password=asdasd;"

Trusted Connection:

"Provider=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 later

Specifying username and password:

"Data Source=MyOracleDB;User Id=username;Password=passwd;Integrated Security=no;"

This one works only with Oracle 8i release 3 or later

Declare the OracleConnection:

C#:

using System.Data.OracleClient;

OracleConnection oOracleConn = new OracleConnection();

oOracleConn.ConnectionString = "my connection string";

oOracleConn.Open();

https://www.doczj.com/doc/4a7879646.html,:

Imports System.Data.OracleClient

Dim oOracleConn As OracleConnection = New OracleConnection()

oOracleConn.ConnectionString = "my connection string"

oOracleConn.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# Corner Core Labs 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;user id=username;password=mypw"

Want to learn data shaping? Check out 4GuyfFromRolla's great article about Data Shaping >> MySQL

MyODBC

MyODBC 2.50 Local database:

"Driver={mySQL};Server=localhost;Option=16834;Database=mydatabase;"

MyODBC 2.50 Remote database:

"Driver={mySQL};Server=https://www.doczj.com/doc/4a7879646.html,;Port=3306;Option=131072;Stmt=;Database=my-dat abase;Uid=username;Pwd=password;"

MyODBC 3.51 Local database:

"DRIVER={MySQL ODBC 3.51 Driver};SERVER=localhost;DA TABASE=myDatabase;USER=myUsername;PASSWORD=myPa ssword;OPTION=3;"

MyODBC 3.51 Remote database:

"DRIVER={MySQL ODBC 3.51 Driver};SERVER=https://www.doczj.com/doc/4a7879646.html,;PORT=3306;DA TABASE=myDatabase;

USER=myUsername;PASSWORD=myPassword;OPTION=3;"

OLE DB, OleDbConnection (.NET)

Standard:

"Provider=MySQLProv;Data Source=mydb;User Id=UserName;Password=asdasd;"

Connector/Net 1.0 (.NET)

Standard:

"Server=Server;Database=Test;Uid=UserName;Pwd=asdasd;"

Download the driver at MySQL Developer Zone.

Specifying port:

"Server=Server;Port=1234;Database=Test;Uid=UserName;Pwd=asdasd;"

Default port is 3306. Enter value -1 to use a named pipe connection.

Declare the MySqlClient connection:

C#:

using MySql.Data.MySqlClient;

MySqlConnection oMySqlConn = new MySqlConnection();

oMySqlConn.ConnectionString = "Server=Server;Database=Test;Uid=UserName;Pwd=asdasd;"; oMySqlConn.Open();

https://www.doczj.com/doc/4a7879646.html,:

Imports MySql.Data.MySqlClient

Dim oMySqlConn As MySqlConnection = New MySqlConnection()

oMySqlConn.ConnectionString = "Server=Server;Database=Test;Uid=UserName;Pwd=asdasd;" oMySqlConn.Open()

MySqlConnection (.NET)

eInfoDesigns.dbProvider:

"Data Source=server;Database=mydb;User ID=username;Password=pwd;Command Logging=false"

This one is used with eInfoDesigns dbProvider, an add-on to .NET

Declare the MySqlConnection:

C#:

using eInfoDesigns.dbProvider.MySqlClient;

MySqlConnection oMySqlConn = new MySqlConnection();

oMySqlConn.ConnectionString = "my connection string";

oMySqlConn.Open();

https://www.doczj.com/doc/4a7879646.html,:

Imports eInfoDesigns.dbProvider.MySqlClient

Dim oMySqlConn As MySqlConnection = New MySqlConnection()

oMySqlConn.ConnectionString = "my connection string"

oMySqlConn.Open()

SevenObjects MySqlClient (.NET)

Standard:

"Host=server; UserName=myusername; Password=mypassword;Database=mydb;"

This is a freeware https://www.doczj.com/doc/4a7879646.html, data provider from SevenObjects

Core Labs MySQLDirect (.NET)

Standard:

"User ID=root; Password=pwd; Host=localhost; Port=3306; Database=test;Direct=true; Protocol=TCP; Compress=false; Pooling=true; Min Pool Size=0;Max Pool Size=100; Connection Lifetime=0"

Read more at Core Lab and the product page.

Interbase

ODBC, Easysoft

Local computer:

"Driver={Easysoft IB6 ODBC};Server=localhost;Database=localhost:C:\mydatabase.gdb;Uid=username;Pwd=password"

Remote Computer:

"Driver={Easysoft IB6 ODBC};Server=ComputerName;Database=ComputerName:C:\mydatabase.gdb;Uid=username;P wd=password"

Read more about this driver: Easysoft ODBC-Interbase driver >>

ODBC, Intersolv

Local computer:

"Driver={INTERSOLV InterBase ODBC Driver (*.gdb)};Server=localhost;Database=localhost:C:\mydatabase.gdb;Uid=username;Pwd=password"

Remote Computer:

"Driver={INTERSOLV InterBase ODBC Driver (*.gdb)};Server=ComputerName;Database=ComputerName:C:\mydatabase.gdb;Uid=username;P wd=password"

This driver are provided by DataDirect Technologies >> (formerly Intersolv)

OLE DB, SIBPROvider

Standard:

"provider=sibprovider;location=localhost:;data source=c:\databases\gdbs\mygdb.gdb;user id=SYSDBA;password=masterkey"

Specifying character set:

"provider=sibprovider;location=localhost:;data source=c:\databases\gdbs\mygdb.gdb;user id=SYSDBA;password=masterkey;character set=ISO8859_1"

Specifying role:

"provider=sibprovider;location=localhost:;data source=c:\databases\gdbs\mygdb.gdb;user id=SYSDBA;password=masterkey;role=DIGITADORES"

Read more about SIBPROvider >>

Read more about connecting to Interbase in this Borland Developer Network article https://www.doczj.com/doc/4a7879646.html,/article/0,1410,27152,00.html

IBM DB2

OLE DB, OleDbConnection (.NET) from ms

TCP/IP:

"Provider=DB2OLEDB;Network Transport Library=TCPIP;Network Address=XXX.XXX.XXX.XXX;Initial Catalog=MyCtlg;Package Collection=MyPkgCol;Default Schema=Schema;User ID=MyUser;Password=MyPW"

APPC:

"Provider=DB2OLEDB;APPC Local LU Alias=MyAlias;APPC Remote LU Alias=MyRemote;Initial Catalog=MyCtlg;Package Collection=MyPkgCol;Default Schema=Schema;User ID=MyUser;Password=MyPW"

IBM's OLE DB Provider (shipped with IBM DB2 UDB v7 or above)

TCP/IP:

Provider=IBMDADB2;Database=sample;HOSTNAME=db2host;PROTOCOL=TCPIP;PORT=50 000;uid=myUserName;pwd=myPwd;

ODBC

Standard:

"driver={IBM DB2 ODBC DRIVER};Database=myDbName;hostname=myServerName;port=myPortNum;protocol=TCPIP; uid=myUserName; pwd=myPwd"

Sybase

ODBC

Standard Sybase System 12 (or 12.5) Enterprise Open Client:

"Driver={SYBASE ASE ODBC Driver};Srvr=Aron1;Uid=username;Pwd=password"

Standard Sybase System 11:

"Driver={SYBASE SYSTEM 11};Srvr=Aron1;Uid=username;Pwd=password;Database=mydb" For more information check out the Adaptive Server Enterprise Document Sets

Intersolv 3.10:

"Driver={INTERSOLV 3.10 32-BIT Sybase};Srvr=Aron1;Uid=username;Pwd=password;"

Sybase SQL Anywhere (former Watcom SQL ODBC driver):

"ODBC; Driver=Sybase SQL Anywhere 5.0; DefaultDir=c:\dbfolder\;Dbf=c:\mydatabase.db;Uid=username;Pwd=password;Dsn="""""

Note! The two double quota following the DSN parameter at the end are escaped quotas (VB syntax), you may have to change this to your language specific escape syntax. The empty DSN parameter is indeed critical as not including it will result in error 7778.

Read more in the Sybase SQL Anywhere User Guide (see part 3, chapter 13) >>

OLE DB

Adaptive Server Anywhere (ASA):

"Provider=ASAProv;Data source=myASA"

Read more in the ASA User Guide (part 1, chapter 2) >>

Adaptive Server Enterprise (ASE) with Data Source .IDS file:

"Provider=Sybase ASE OLE DB Provider; Data source=myASE"

Note that you must create a Data Source .IDS file using the Sybase Data Administrator. These .IDS files resemble ODBC DSNs.

Adaptive Server Enterprise (ASE):

"Provider=Sybase.ASEOLEDBProvider;Srvr=myASEserver,5000;Catalog=myDBname;User

Id=username;Password=password"

- some reports on problem using the above one, try the following as an alternative -

"Provider=Sybase.ASEOLEDBProvider;Server Name=myASEserver,5000;Initial Catalog=myDBname;User Id=username;Password=password"

This one works only from Open Client 12.5 where the server port number feature works,?allowing fully qualified connection strings to be used without defining?any .IDS Data Source files. AseConnection (.NET)

Standard:

"Data

Source='myASEserver';Port=5000;Database='myDBname';UID='username';PWD='password';"

Declare the AseConnection:

C#:

using Sybase.Data.AseClient;

AseConnection oCon = new AseConnection();

oCon.ConnectionString="my connection string";

oCon.Open();

https://www.doczj.com/doc/4a7879646.html,:

Imports System.Data.AseClient

Dim oCon As AseConnection = New AseConnection()

oCon.ConnectionString="my connection string"

oCon.Open()

Read more! Adaptive Server Enterprise https://www.doczj.com/doc/4a7879646.html, Data Provider Documentation >>

Informix

ODBC

Informix 3.30:

"Dsn='';Driver={INFORMIX 3.30 32 BIT};Host=hostname;Server=myserver;Service=service-name;Protocol=olsoctcp;Database=mydb ;UID=username;PWD=myPwd

Informix-CLI 2.5:

"Driver={Informix-CLI 2.5 (32 Bit)};Server=myserver;Database=mydb;Uid=username;Pwd=myPwd"

OLE DB

IBM Informix OLE DB Provider:

"Provider=Ifxoledbc.2;password=myPw;User ID=myUser;Data Source=dbName@serverName;Persist Security Info=true"

Ingres

ODBC

DSN-less

"Provider=MSDASQL.1;DRIVER=Ingres;SRVR=xxxxx;DB=xxxxx;Persist Security Info=False;uid=xxxx;pwd=xxxxx;SELECTLOOPS=N;Extended

Properties="""SERVER=xxxxx;DATABASE=xxxxx;SERVERTYPE=INGRES""

Mimer SQL

ODBC

Standard Security:

"Driver={MIMER};Database=mydb;Uid=myuser;Pwd=mypw;"

SQL数据库基础知识集合

1、数据库简介: 数据库是专门开发数据管理的软件,或者说专门管理数据的软件就是数据库。 数据库存在的意义就是:减轻开发人员的负担。数据库是一个综合的软件,那么我们不需要队要进行2进制保存数据进行处理了,但是却是要与数据库产生交互,那么命令式SQL,有技巧的,数据库就是万物皆关系(面向对象,万物皆是对象)有所区别。 2、数据库的发展: 一开始的是层次化的数据与网状数据库,后来也发现使用确实很麻烦。 于是到了1970年EF.Cold博士(IBM公司的研究员)开创了关系性的数据库的先驱,发表了关系性数据库的论文,但是由于当时电脑硬件的局限性,大家觉得跑如此大的程序不值得。后来,Oracle(甲骨文)公司的创始人,拉里带领Oracle投入到关系型数据库的研发,并且得到了一个大客户—美国国防部。随即开始世界刮起了关系数据库的旋风,随后各个公司都纷纷推出自己的数据库系统。比如:IBM的DB2 ,还有风靡一时的DBS3。 但是随即出现不兼容的问题,由于最早的时候都没有进行没规范。所以到最后各个数据库巨头统一了操纵数据库的SQL(结构化Struct数据查询语言)变成了标准语言,而关系型数据库也俨然变成大家的宠儿,Oracle也从一个小公司,变成现在的数据库巨头,而我们的微软也推出了SQLServer。当然还有PHPer的最爱mySQL。但是mySQL被SUN,SUN 被Oracle收购,现在有免费版与收费专业版了。所以我们学习SQL语言的时候,先学共同点,再学特异性。各种数据库软件在使用上有一点区别。 3、数据库系统详解: 为适应数据处理的需要而发展起来的一种较为理想的数据处理的核心机构。计算机的高速处理能力和大容量存储器提供了实现数据管理自动化的条件。 数据库系统一般由4个部分组成: 数据库,即存储在磁带、磁盘、光盘或其他外存介质上、按一定结构组织在一起的相关数据的集合。(个体) 数据库管理系统(DBMS)。一组能完成描述、管理、维护子数据库的程序系统。它按照一种公用的和可控制的方法完成插入新数据、修改和检索原有数据的操作。 数据库管理员(DBA)。 用户和应用程序。(微软的称作SSMS) 4、数据库系统的基本要求是: 1、能够保证数据的独立性。数据和程序相互独立有利于加快软件开发速度,节省开发费用。 2、冗余数据少,数据共享程度高。 3、系统的用户接口简单,用户容易掌握,使用方便。 4、能够确保系统运行可靠,出现故障时能迅速排除,能够保护数据不受非受权者访问或破坏,能够防止错误数据的产生,一旦产生也能及时发现。 5、有重新组织数据的能力,能改变数据的存储结构或数据存储位置,以适应用户操作特性的变化,改善由于频繁插入、删除操作造成的数据组织零乱和时空性能变坏的状况。 6、具有可修改性和可扩充性、可维护性。 7、能够充分描述数据间的内在联系。 5、数据库(Database): 由众多的数据、数据表、约束、存储过程、函数、视图、索引构成的一个数据存储与交互单元,是按照数据结构来组织、存储和管理数据的仓库。 6、数据表(table): 数据表,实际上是一个二维表。一般是围绕一个事务、动作记录,或者是一个信息主题作为一个数据表。数据表由行与列构成。 7、列(column、field): 列,其实就是字段。也是决定了信息的基本单元。列,包含有数据类型的设定。 8、行(row、record): 行,实际上就是一条基本信息。一行包含了多列数据的存储的信息。所以一行也有一条记录之称。 9、行业(trade) 一个行业一种需求,没一个需求每一种数据库的设计模式与思想。每个行业的数据设计的重点都是不同的。侧重查询(要求低范式)还是操作(要求搞范式)就是自己选择的问题了。 10、索引(index) 索引是一个单独的、物理的数据库结构,它是某个表中一列或若干列值的集合和相应的指向表中物理标识这些值的数据页的逻辑指针清单。索引其实就是一个B+树,但是这个索引是N^n层数次方的。目的就是在数据库中划分出一定的区域优化查询。可以提升大量数据的查询速度。索引一般可以分为:基于字段优化查询速度的普通索引、唯一性索引、主键索引、全文索引、单列与多列索引。现在由于数据库系统的不断升级,我们只要设定索引就可以了,不需要特殊的维护。而且数据在查询的时候也会根据查询适当地选择是利用索引查询,还是仅仅是表查询。由于数据库系统的发展,系统内部已经自动帮我们完成对索引的维护。但是在设计的时候要考虑到索引的损耗问题。数据库DB就像是一个字典,索引就是根据指定字段制成的快速指向。由于只是指向数据对象标识,真正的数据是存储在DB中,所以查询速度极快。但是额外的内存与硬盘花销也是一个需要考虑的问题。比如:增加、删除、修改时数据库都要对索引进行维护,但是这样也是为了最后查询的效率的提升,特别适合W行级别的数据查询。而索引可以分为:隐式索引(针对单个字段)、唯一索引(唯一约束)、函数索引(函数(字段))、聚簇索引(主键)、组合索引(最多16个field)与全文索引(text)。一般索引会占用原数据库大小的20%。 11、视图(view) 固化的子查询,将一个子查询起了一个固化的名字,保存在数据库中,方便以后的使用。其实调用大量的Join来进行一个查询一般也是用视图。视图与索引都是为了优化查询的速度与语句。视图是优化语句,索引是优化单查速度。一般是DBA来设定数据库的视图,封装内部数据库的数据关系,范式修改数据容易了,视图让我们查询复杂关系的数据变得容易。 12、触发器(trigger) 触发器(trigger)是个特殊的存储过程,它的执行不是由程序调用,也不是手工启动,而是由个事件来触发,比如当对一个表进行操作(insert,delete,update)时就会激活它执行。触发器经常用于加强数据的完整性约束和业务规则等。触发器可以从DBA_TRIGGERS ,USER_TRIGGERS 数据字典中查到。 13、SQLServer数据类型详解

SQL银行数据库管理语句(详细版)

create table UserInfo( CustomerId char(20), CustomerName char(50)not null, PID varchar(20)unique, Telephone varchar(20), Address char(50), PRIMARY KEY(CustomerId)) create table CardInfo( cardID char(50)not null, curType varchar(10)not null default'RMB', savingType varchar(10), openDate datetime default getdate(), openMoney int not null, balance int not null, pass char(50)not null default'888888', IsReportLoss char(50)not null default'否', customerID char(20)not null foreign key(customerID)references userinfo(customerID), PRIMARY KEY(CardId)) create table TransInfo( transDate datetime not null default'getdate()', cardID char(50)foreign key(cardID)references cardinfo(cardID), transType char(10)not null, transMoney bigint not null, remark char(20), ID int identity(1,1)not null) Insert into userinfo values('10001','李清','420101************','2071-84216821','湖北武汉'); Insert into userinfo values('10002','玉清','420101************','2071-84216820','湖北武汉'); INSERT INTO CardInfo V ALUES('102128001','RMB','活期',getdate(),'10000','10000','84212121','否','10001'); INSERT INTO CardInfo V ALUES('102128002','RMB','活期',getdate(),'10001','10001','84202020','否','10002');

ASP NET 6种常用数据库的连接方法

1.C#连接连接Access 程序代码: using System.Data; using System.Data.OleDb; .. string strConnection="Provider=Microsoft.Jet.OleDb.4.0;"; strConnection+=@"Data Source=C:BegASPNETNorthwind.mdb"; OleDbConnection objConnection=new OleDbConnection(strConnection); .. objConnection.Open(); objConnection.Close(); 解释: 连接Access数据库需要导入额外的命名空间,所以有了最前面的两条using命令,这是必不可少的! strConnection这个变量里存放的是连接数据库所需要的连接字符串,他指定了要使用的数据提供者和要使用的数据源. "Provider=Microsoft.Jet.OleDb.4.0;"是指数据提供者,这里使用的是Microsoft Jet引擎,也就是Access中的数据引擎,https://www.doczj.com/doc/4a7879646.html,就是靠这个和Access的数据库连接的. "Data Source=C:\BegASPNET\Northwind.mdb"是指明数据源的位置,他的标准形式是"Data

Source=MyDrive:MyPath\MyFile.MDB". PS: 1."+="后面的"@"符号是防止将后面字符串中的"\"解析为转义字符. 2.如果要连接的数据库文件和当前文件在同一个目录下,还可以使用如下的方法连接: strConnection+="Data Source="; strConnection+=MapPath("Northwind.mdb"); 这样就可以省得你写一大堆东西了! 3.要注意连接字符串中的参数之间要用分号来分隔. "OleDbConnection objConnection=new OleDbConnection(strConnection);"这一句是利用定义好的连接字符串来建立了一个链接对象,以后对数据库的操作我们都要和这个对象打交道. "objConnection.Open();"这用来打开连接.至此,与Access数据库的连接完成. 2.C#连接SQL Server 程序代码: using System.Data; using System.Data.SqlClient; .. string strConnection="user id=sa;password=;"; strConnection+="initial catalog=Northwind;Server=YourSQLServer;";

sql数据库期末考试题及答案

一、单选题(共 10 道试题,共 50 分。)V 1. SQL Server中,保存着每个数据库对象的信息的系统表是()。 A. sysdatabases B. Syscolumns C. Sysobjects D. Syslogs 满分:5 分 2. 在存在下列关键字的SQL语句中,不可能出现Where子句的是()。 A. Update B. Delete C. Insert D. Alter 满分:5 分 3. 在查询语句的Where子句中,如果出现了“age Between 30 and 40”,这个表达式等同于()。 A. age>=30 and age<=40 B. age>=30 or age<=40 C. age>30 and age<40 D. age>30 or age<40 满分:5 分 4. 如果要在一管理职工工资的表中限制工资的输入围,应使用()约束。 A. PDRIMARY KEY B. FOREIGN KEY C. unique D. check 满分:5 分 5. 记录数据库事务操作信息的文件是()。 A. 数据文件 B. 索引文件 C. 辅助数据文件 D. 日志文件 满分:5 分 6. 要查询XSH数据库CP表中产品名含有“冰箱”的产品情况,可用()命令。 A. SELECT * FROM CP WHERE 产品名称LIKE ‘冰箱’ B. SELECT * FROM XSH WHERE 产品名称LIKE ‘冰箱’ C. SELECT * FROM CP WHERE 产品名称LIKE ‘%冰箱%’ D. SELECT * FROM CP WHERE 产品名称=‘冰箱’ 满分:5 分 7. 储蓄所有多个储户,储户能够在多个储蓄所存取款,储蓄所与储户之间是()。 A. 一对一的联系 B. 一对多的联系 C. 多对一的联系 D. 多对多的联系 满分:5 分

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为数据库的SID user="test"; password="test"; 3、连接SQLServer2005 Class.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";

java平时最常用的7种数据库连接方式

今天总结了java平时最常用的7种数据库连接方式,现在分享给大家 MySQL: String Driver="com.mysql.jdbc.Driver"; //驱动程序 String URL="jdbc:mysql://localhost:3306/db_name"; //连接的URL,db_name 为数据库名 String Username="username"; //用户名 String Password="password"; //密码 Class.forName(Driver).new Instance(); Connection con=DriverManager.getConnection(URL,Username,Password); Microsoft SQL Server: 1) String Driver="com.microsoft.jdbc.sqlserver.SQLServerDriver"; //连接SQL数据库的方法 String URL="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=db_name"; //db_name为数据库名 String Username="username"; //用户名 String Password="password"; //密码 Class.forName(Driver).new Instance(); //加载数据可驱动 Connection con=DriverManager.getConnection(URL,UserName,Password); // 2) String Driver="com.microsoft.sqlserver.jdbc.SQLServerDriver"; //连接SQL数据库的方法 String URL="jdbc:sqlserver://localhost:1433;DatabaseName=db_name"; //db_name为数据库名 String Username="username"; //用户名 String Password="password"; //密码 Class.forName(Driver).new Instance(); //加载数据可驱动 Connection con=DriverManager.getConnection(URL,UserName,Password); Sysbase: String Driver="com.sybase.jdbc.SybDriver"; //驱动程序 String URL="jdbc:Sysbase://localhost:5007/db_name"; //db_name为数据可名 String Username="username"; //用户名 String Password="password"; //密码 Class.forName(Driver).newInstance(); Connection con=DriverManager.getConnection(URL,Username,Password); Oracle(用thin模式): String Driver="oracle.jdbc.driver.OracleDriver"; //连接数据库的方法String URL="jdbc:oracle:thin:@loaclhost:1521:orcl"; //orcl为数据库的SID String Username="username"; //用户名 String Password="password"; //密码 Class.forName(Driver).newInstance(); //加载数据库驱动

数据库连不上

不允许交叉联接问题 错误原因:没有建立连接 RQP-DEF-0103错误 对于具有以下身份的用户而言,不允许使用交叉联接(查询主题之间:[测试].[test_li], [测试.[test_lj]):{所有经过验证的用户, 任何人, 创建者, 查询用户, 客户, 度量标准创建者, 度量标准用户, 这个方法好极了: 方法1:在报表端处理一下,就是选中你交叉表所用的查询,设置属性“允许向量乘积”设置为允许就可以了 (查看->查询) 方法2:在FM界面的project菜单中,选中Edit Governors,在弹出的页面中把Cross-Product joins设为Allow 在与SQL Server 建立连接时出现与网络相关的或特定于实例的错误。未找到或无法访问服务器。请验证实例名称是否正确并且SQL Server 已配置为允许远程连接。(provider: 命名管道提供程序, error: 40 - 无法打开到SQL 1.开启sql2005远程连接功能,开启办法如下: 配置工具->Sql Server外围应用配置器->服务和连接的外围应用配置器->打开MSSQLSERVER节点下的Database Engine节点,先择“远程连接”,接下建议选择“同时使用TCP/IP和named pipes”,确定后重启数据库服务就可以了。 2.登陆设置改为:Sql Server 和Windows 身份验证模式,具体设置如下: SQL Server Management Studio管理器->Windows 身份验证连接服务器->对象资源管理器中选择你的数据服务器->右键->属性->安全性->Sql Server 和Windows 身份验证模式选中。 3.设置一个Sql Server方式的用户名和密码,具体设置如下: (1)SQL Server Management Studio管理器->Windows 身份验证连接服务器->对象资源管理器中选择你的数据服务器->展开服务器上的“安全性”->登陆名->在sa帐号上点右键->“选择页”选择常规->更改sa登陆帐号的密码。这样就设置了一个用户名为sa,密码为:sa123456的用户。 (2)“选择页”选择状态->登陆修改为启用 4.数据库连接字符串 数据库连接字符串有好几种,相信你自己也见过,都被搞晕了 Data Server=./SQLEXPRESS;Initial Catalog=Northwind;User ID=sa;Password=sa123456 Data Server=服务器名/SQLEXPRESS;Initial Catalog=Northwind;User ID=sa;Password=sa123456 Data Server=localhost/SQLEXPRESS;Initial Catalog=Northwind;User

通过ADO连接各种数据库的字符串

通过ADO连接各种数据库的字符串 在网络编程过程中,ADO(Activex Data Object)编程往往是不可少的工作,特别是开发电子商务网站。既然讲到ADO数据对象,那么就顺便简单地介绍一下ADO数据对象及其功能。ADO数据对象共有七种独立的对象,他们分别是连接对象(Connection)、记录集对象(RecordSet)、域对象(Field)、命令对象(Command)、参数对象(Parameter)、属性对象(Property)和错误对象(Error)。功能请参见附录1。 ADO数据对象用来连接数据库的方式有两种,分别是ODBC和OLE DB方式,下面就分别介绍用这两种方式连接数据库的例子。 第一种:ODBC DSN-Less Connections ODBC Driver for Access ODBC Driver for dBASE ODBC Driver for Excel ODBC Driver for MySQL ODBC Driver for Oracle ODBC Driver for Paradox ODBC Driver for SQL Server ODBC Driver for Sybase ODBC Driver for Sybase SQL Anywhere ODBC Driver for Text ODBC Driver for Teradata ODBC Driver for Visual FoxPro 第二种:OLE DB Data Provider Connections OLE DB Provider for Active Directory Service OLE DB Provider for DB2 OLD DB Provider for Internet Publishing OLE DB Provider for Index Server OLE DB Provider for Microsoft Jet OLE DB Provider for ODBC Databases OLE DB Provider for Oracle (From Microsoft) OLE DB Provider for Oracle (From Oracle)

7种方法连接数据库

连接数据库的方法小结 1.ODBC API ODBC(Open Database Connectivity,开放数据库互连)是微软公司开放服务结构(WOSA,Windows Open Services Architecture)中有关数据库的一个组成部分,它建立了一组规范,并提供了一组对数据库访问的标准API(应用程序编程接口)。这些API利用SQL来完成其大部分任务。ODBC本身也提供了对SQL语言的支持,用户可以直接将SQL语句送给ODBC。 一个基于ODBC的应用程序对数据库的操作不依赖任何DBMS,不直接与DBMS打交道,所有的数据库操作由对应的DBMS的ODBC驱动程序完成。也就是说,不论是FoxPro、Access , MYSQL还是Oracle数据库,均可用ODBC API 进行访问。由此可见,ODBC的最大优点是能以统一的方式处理所有的数据库。 2.MFC ODBC 由于直接使用ODBC API编写应用程序要编制大量代码,开发者往往需要花费很多的精力在非核心代码的维护上,而Visual C++提供了MFC ODBC类,封装了ODBC API,这使得利用MFC ODBC来创建ODBC应用程序非常简便。 3.DAO(Data Access Object) DAO提供了一种通过程序代码创建和操纵数据库的机制,多个DAO构成一个体系结构,在这个体系结构中,各个DAO对象协同工作。MFC DAO是Microsoft提供的用于访问Microsoft jet数据库文件的强有力的数据库开发工具,它通过封装DAO,向程序员提供了DAO操作数据库的手段。 4.OLE DB OLE DB(Object Linking and Embedding, Database, 又称为OLE DB或OLE-DB),一个基于COM的数据存储对象,能提供对所有类型的数据的操作,甚至能在离线的情况下存取数据(比方说,你使用的是你的便携机,你可以毫不费力地看到最后一次数据同步时的数据映像). OLEDB位于ODBC层与应用程序之间. 在你的ASP页面里,ADO是位于OLEDB之上的应用程序. 你的ADO调用先被送到OLEDB,然后再交由ODBC 处理. 你可以直接连接到OLEDB层,如果你这么做了,你将看到服务器端游标(recordset的缺省的游标,也是最常用的游标)性能的提升.

ODBC和OleDb访问数据库的连接字符串

C# 中ODBC和OleDb访问数据库的连接字符串 因为工作需要自学数据库的访问,查看相关书籍时,都是以OleDb类进行.Net开发为例,虽然也提到ODBC和OleDb在原理上是一样,但是没有实际的例子,而我恰恰需要通过ODBC来访问数据库,这就碰到连接字符串问题,下面介绍一种简单的查找连接字符串的方法,前提是你用的是VisualStudio开发工具。 步骤一:先在控制面板的数据源ODBC中设定好系统DSN,方法如下; 打开“控制面板”—>“管理工具”—>“数据源(ODBC)”,打开“ODBC 数据源管理器”,设置系统DSN或用户DSN。 单击“添加”按钮进入创建新数据源,选择数据源的驱动程序,因为我要演示的是通过ODBC访问本地Access数据库,所以此处选择“Microsoft for Access Driver(*mdb,*accdb)”,其中mdb文件的Access是Access2003数据库文件的后缀,accdb文件Access2007和以上版本数据库文件的后缀,accdb文件转换为mdb需要在Office2007中打开accdb文件然后另存为Access2003数据库,后缀名自动变为mdb,这两种格式的文件数据库连接组件不一样。 当然你也可以通过ODBC访问SQL Serve等其他数据库,虽然使用ODBC能以统一的方式处理所有的数据库,但是使用ODBC来进行.NET开发的时候,其速度要比OleDB、SQL Server慢很多。

选择数据源的驱动程序后自动跳入下面界面,“数据源名”自己设定,此处命名为DataBase,在“数据库”中点击“选择”,选择需要通过ODBC连接的数据库,选择好后在“数据库:”右侧会显示数据库的路径如图。 单击“确定”后返回“ODBC数据源管理器”,此时在系统数据源中已经添加了一个名称为“DataBase”的“Microsoft for Access Driver(*mdb,*accdb)”的驱动程序。点击“确定”关闭该界面。

SQL2008数据库使用手册

SQL数据库用户使用手册 如何将本地SQL数据库导入到万网主机上,一般分为4个步骤 示例: 第一步:通过SQL脚本生成表结构,可以保证本地数据库中视图、存储过程、以及表的默认值、标识、主键等属性的完整性,避免由于DTS传输引起丢失属性的问题,同时使用查询分析器执行SQL脚本,在服务器端创建表结构; 1)、请您先运行本地的企业管理器 2)、请您点击您本地的数据库点击右健-》选择生成SQL脚本

3)、选择常规-》点击全部显示,选择您想导出的脚本对象 4)、点击选项-》表脚本选项,把您所用到的脚本选中然后点击确定 5)为自己导入的.sql脚本文件命名,并保存在本地

6)、找到刚才我们保存在本地的.sql脚本文件,使用记事本打开 7)、选择编辑-》替换,把程序中所有[dbo]的字符都更改成您万网发信告知您的数据库登

陆名,更换完成后保存关闭记事本 8)、通过万网通知书中的数据库登陆地址、数据库登陆名、和数据库密码,使用企业管理器连接到万网的主机服务器上,然后选择查询分析器

9)、点击打开选择刚才编辑过的.sql脚本,然后点击运行 第二步:在本地创建一个和万网主机相同权限的SQL数据库 1)、完成上面操作后,请您选择数据库点击右键选择新建数据库,由于您在万网申请的是虚拟主机,万网分配的权限都是user的而不是dbo的权限,因此需要您在本地也创建一个与服务器一样的配置,以便正常完成导入操作

2)、在常规-》名称处输入万网开通通知中告知您的数据库库名,然后点击确定。例如:cw01001_db 3)、选择安全性-》新建登陆

C#数据库连接操作大全

C#数据库连接操作大全 下面是c#与数据库的连接及增删改除的各种操作,全部经过上机验证。本人是从事软件开发,如果各位有什么问题或者需要帮助的可以在我的空间留言。 一:数据库连接代码: SqlConnection objSqlConnection = new SqlConnection ("server = 127.0.0.1;uid = sa; pwd =;database =test"); objSqlConnection.Open(); 二:数据库的添加记录代码: int i = 0; string s1 = "", s2 = ""; i = Convert.ToInt16(textBox1.Text); s1 = textBox2.Text; s2 = textBox3.Text; SqlConnection objSqlConnection = new SqlConnection("server = 127.0.0.1;uid = sa; pwd =;database =test"); objSqlConnection.Open(); MessageBox.Show("数据库连接成功", "好"); try { SqlCommand sqlcom = new SqlCommand("insert into info(id,name,sex) values( " + i + ",'" + s1 + "','" + s2 + "')", objSqlConnection); sqlcom.ExecuteNonQuery(); MessageBox.Show("添加成功!", "啊"); } catch (Exception a) { MessageBox.Show(a.ToString()); } MessageBox.Show("添加成功!", "啊"); } 三:数据库的修改代码: int i = 0; string s1 = "", s2 = ""; s1 = textBox2.Text; s2 = textBox3.Text; if (textBox1.Text.Length == 0) i = 0; else i = Convert.ToInt32(textBox1.Text);

数据库连接字符串

/数据库连接字符串(web.config来配置),可以动态更改connectionString支持多数据库. public static string connectionString = System.Configuration.ConfigurationManager.C onnectionStrings["ConnectionString"].ConnectionString; ///

///执行存储过程,返回SqlDataReader ( 注意:调用该方法后,一定要对SqlDataReader进行Close ) /// ///存储过程名 ///存储过程参数 ///SqlDataReader public static SqlDataReader RunProcedure(string storedProcName, IDataParamet er[] parameters) { SqlConnection connection = new SqlConnection(connectionString); SqlDataReader returnReader; connection.Open(); SqlCommand command = BuildQueryCommand(connection, storedProcName, parameters); https://www.doczj.com/doc/4a7879646.html,mandType = CommandType.StoredProcedure; returnReader = command.ExecuteReader(CommandBehavior.CloseConnection ); return returnReader; } /// ///执行存储过程 /// ///存储过程名 ///存储过程参数 ///DataSet结果中的表名 ///DataSet public static DataSet RunProcedure(string storedProcName, IDataParameter[] pa rameters, string tableName) {

数据库连接字符串详解

SQLserver: 命名空间应用:using System.Data; using System.Data.SqlClient; 字符串:@"Server=服务器名;Database=数据库名;User ID=用户名;Password=密码;" window身份验证字符串写法:@"Data Source=.;Initial Catalog=数据库名;Integrated Security=True" SQL身份验证:字符串写法 @"server=.;database=ReportServer;uid=sa;pwd=sa" access: 命名空间应用:using System.Data; using System.Data.OleDb; 字符串:@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=数据库的物理路径;User ID=用户名;Password=你的密码;" 无密码字符串:@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=数据库的物理路径;" 注解:1. “@”符号用于防止将后面字符串中的“\”解析为转义字符。也就是回车“\n” 2. (local)表示本地 3. Application.StartupPath相对路径 可添加属性:(在字符串中可以添加的属性,用";"符号分开即可) 1. Persist Security Info=false/true 在数据库连接成功后是否保存密码信息,True表示保存,False表示不保存 https://www.doczj.com/doc/4a7879646.html,中默认情况下为false 2. Connect Timeout=分钟数设定多少分钟之后过期 附录: 1关键字 其中一些关键字及其值的说明:(关键字不区分大小写) 1.Connect Timeout 表示连接超时的意思,即在终止尝试并产生错误之前,等待与服务器的连接的时间长度(以秒为单位),默认值为15. 2.Data Source 或 Server 两个关键字都代表同一个意义,即要连接的SQL Server实例的名称或网络地址。 3.Initial Catalog 或 Database 两个关键字都代表同一个意义,即数据库的名称。如果连接的是本地的服务器,既可以写本地服务器的名字,也可写"localhost"或"(local)"。 4.Integrated Security 或Trusted_Connection 两个关键字都代表同一个意义,即是否使用Windows集成安全身份认证。当其值为False

SQL数据库连接字符串大全

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") = adPromptAlways oConn.Open "Driver={SQL Server};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 serverName\instanceName as Data Source to use an specifik SQLServer instance, only SQLServer2000) Prompt for username and password: oConn.Provider = "sqloledb" oConn.Properties("Prompt") = adPromptAlways oConn.Open "Data Source=Aron1;Initial Catalog=pubs;"

SQL数据库完全操作手册

SQL数据库完全操作手册 SQL是Structured Quevy Language(结构化查询语言)的缩写。SQL是专为数据库而建立的操作命令集,是一种功能齐全的数据库语言。在使用它时,只需要发出“做什么”的命令,“怎么做”是不用使用者考虑的。SQL功能强大、简单易学、使用方便,已经成为了数据库操作的基础,并且现在几乎所有的数据库均支持SQL。 ##1 二、SQL数据库数据体系结构 SQL数据库的数据体系结构基本上是三级结构,但使用术语与传统关系模型术语不同。在SQL中,关系模式(模式)称为“基本表”(base table);存储模式(内模式)称为“存储文件”(stored file);子模式(外模式)称为“视图”(view);元组称为“行”(row);属性称为“列”(column)。名称对称如^00100009a^: ##1 三、SQL语言的组成 在正式学习SQL语言之前,首先让我们对SQL语言有一个基本认识,介绍一下SQL 语言的组成: 1.一个SQL数据库是表(Table)的集合,它由一个或多个SQL模式定义。 2.一个SQL表由行集构成,一行是列的序列(集合),每列与行对应一个数据项。 3.一个表或者是一个基本表或者是一个视图。基本表是实际存储在数据库的表,而视图是由若干基本表或其他视图构成的表的定义。 4.一个基本表可以跨一个或多个存储文件,一个存储文件也可存放一个或多个基本表。每个存储文件与外部存储上一个物理文件对应。 5.用户可以用SQL语句对视图和基本表进行查询等操作。在用户角度来看,视图和基本表是一样的,没有区别,都是关系(表格)。 6.SQL用户可以是应用程序,也可以是终端用户。SQL语句可嵌入在宿主语言的程序中使用,宿主语言有FORTRAN,COBOL,PASCAL,PL/I,C和Ada语言等。SQL用户也能作为独立的用户接口,供交互环境下的终端用户使用。 ##1 四、对数据库进行操作 SQL包括了所有对数据库的操作,主要是由4个部分组成: 1.数据定义:这一部分又称为“SQL DDL”,定义数据库的逻辑结构,包括定义数据库、基本表、视图和索引4部分。 2.数据操纵:这一部分又称为“SQL DML”,其中包括数据查询和数据更新两大类操作,其中数据更新又包括插入、删除和更新三种操作。 3.数据控制:对用户访问数据的控制有基本表和视图的授权、完整性规则的描述,事务控制语句等。 4.嵌入式SQL语言的使用规定:规定SQL语句在宿主语言的程序中使用的规则。下面我们将分别介绍: ##2 (一)数据定义 SQL数据定义功能包括定义数据库、基本表、索引和视图。 首先,让我们了解一下SQL所提供的基本数据类型:(如^00100009b^) 1.数据库的建立与删除 (1)建立数据库:数据库是一个包括了多个基本表的数据集,其语句格式为: CREATE DATABASE <数据库名> [其它参数] 其中,<数据库名>在系统中必须是唯一的,不能重复,不然将导致数据存取失误。[其它参数]因具体数据库实现系统不同而异。 例:要建立项目管理数据库(xmmanage),其语句应为: CREATE DATABASE xmmanage

相关主题
文本预览
相关文档 最新文档