Delphi Connection SQL Server string 2011-10-11 16:07

Source: Internet
Author: User

delphi Connection string for SQL Server 2011-10-11 16:07

First, Delphi connect SQL Server

Put a connection component adoconnection, the other components tadodataset,tadoquery, such as connection point to adoconnection on it.

You can double-click the ADOConnection to use its wizard. You can also use the following code

function Openadoconn:boolean;

Begin

Result:=false;

Try

With ADOConnection do

Begin

Connected:= false;

provider:= ' sqloledb.1 ';

properties[' Data Source '. Value:= HostName; Server name

properties[' Initial Catalog '. Value:= DatabaseName; Table name

properties[' User ID ']. Value:= UserID; User name

properties[' password '. Value:= userpwd; Password

Loginprompt:= false;

Try

connected:= true;

Except

Begin

Application.messagebox (' Can't connect to remote database! ‘

, ' attention ', MB_OK);

Exit

End

End

End

Finally

End

Result:=true;

End

Second, Delphi connection SQL Server 2005

The only key is the connection string, everything else is the same

SQL Server 2005 Standard connection string:

NT Account Login:

PROVIDER=SQLNCLI.1;

Persist Security info=true;

User Id={user ID};

Password={password};

Initial catalog={database name};

Data source={instance name};

SQL Account Login:

PROVIDER=SQLNCLI.1;

Integrated Security=sspi;

Persist Security Info=false;

Initial catalog={database name};

Data source={instance name};

Where the user ID and password are needless to say, respectively, is the username and password

Database name is the name of the databases

The instance name is the name of the instance of SQL Server, and note that this instance must indicate that the user

For example, my Computer name is Rarnu,ip is 192.168.0.100

Then instance name can be filled in rarnu\sqlserver2005 or 192.168.0.100\sqlserver2005

The following SQLSERVER2005 is the instance name specified at installation time.

The next thing is very simple, in Delphi write the following code:

Adoconnection1.connectionstring: =

' Provider=sqlncli.1; ' +

' Integrated Security=sspi; ' +

' Persist Security info=false; ' +

' Initial Catalog=demo; ' +

' Data source=.\sqlexpress; ';

Adoconnection1.open;

Three, the string connecting 2008 database;
/linkconnectionstr: = ' provider=sqlncli10.1; Server= ' +cbdbserver.text+ ';D atabase= ' +cbdbname.text+ '; User id= ' +edtuser.text+ '; password= ' +medtpwd.text+ ';


Linkconnectionstr: = ' provider=sqlncli10.1;integrated security= "; Persist Security Info=false; User id=sa;initial catalog=master;data source= server name \mssql2008;initial File name= ""; Server spn= "";

Delphi Connection SQL Server string 2011-10-11 16:07

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.