First thing is to connect to the server. The server can be a remote server or SQLEXPRESS on local PC.
Please use this function to connect to the server. MSSQL Server/SQLEXPRESS can be configured
to accept logins as user/password or with Windows authentication or both. When configuring it is
desirable to allow user/password based logins. For MSSQL server, built-in adiminstrator account's name is SA, like "root" for MySql.
Syntax:
oCn := FW_OpenAdoConnection( { "MSSQL", cServer, [cDataBase], cUser, cPassword }, lShowError )
OR
oCn := FW_OpenAdoConnection( { "MSSQL,cServer,[cDataBase],cUser,cPassword", lShowError )
When we are connecting for the first time we can ommit database name because we want to create a database after logging in.
Example:
- Code: Select all Expand view
oCn := FW_OpenAdoConnection( { "MSSQL", "PCNAME\SQLEXPRESS",,"SA","secret" }, .t. )
if oCn == nil
? "Connect Fail"
return nil
endif
// proceed using the connection.
// Create a database named FWH
oCn:Execute( "CREATE DATABASE FWH" )
oCn:Close()
Now we can loging with the database name and start creating tables.
In this example, we copy a dbf file to the server to the database FWH, open the table and browse it
- Code: Select all Expand view
oCn := FW_OpenAdoConnection( { "MSSQL", "PCNAME\SQLEXPRESS","FWH","SA","secret" }, .t. )
if oCn == nil
? "Connect Fail"
return nil
endif
FW_AdoImportFromDBF( oCn, "c:\fwh\samples\customer.dbf" )
oRs := FW_OpenRecordSet( oCn, "customer" )
XBROWSER oRs FASTEDIT
oRs:Close()
oCn:Close()
We can continue with more examples depending on your requirements.