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