You can connect to Microsoft SQL Server from PowerBuilder in different ways.
1/ Using SQL Native Client Provide
2/ Using SQL OLEDB Provider
3/ Creating a DSN and using ODBC driver
4/ Using ODBC and default SQL Server provider provided in windows machines
Using SQL Native Client
// Using SQL Native Client
SQLCA.DBMS = "SNC SQL Native Client(OLE DB)" or "SNC"
//Using OLEDB Provider
SQLCA.DBMS = "MSOLEDB"
// below All parameters will be same
SQLCA.Database = "YourDatabase"
SQLCA.ServerName = "YourServer"
SQLCA.LogId = "your_username"
SQLCA.LogPass = "your_password"
SQLCA.AutoCommit = False
SQLCA.DBParm = "Provider='SQLNCLI11',Database='YourDatabase',TrimSpaces=1,StaticBind=0"
If it uses windows authentication, you need to add this parameter and don't use the LogID and LogPass
SQLCA.DBParm = "Provider='SQLNCLI11',Database='YourDatabase',TrimSpaces=1,StaticBind=0,TrustedConnection=1"
// Using ODBC Provider
SQLCA.DBMS = "ODBC"
SQLCA.ServerName = "YourServer"
SQLCA.dbparm="ConnectString='Driver={SQL Server};Server=myServerAddress;Database=myDataBase;PORT=portno;Trusted_Connection=Yes;'"
// If you are using SQL authentication
SQLCA.dbparm="ConnectString=Driver='{SQL Server};Server=myServerName,myPortNumber;Database=myDataBase;Uid=myUsername;Pwd=myPassword;'"
// Also using the ODBC provider you can connect to sqlserver with different types of middleware software like below
SQLCA.DBMS = "ODBC"
SQLCA.AutoCommit = False
SQLCA.DBParm="ConnectString='DRIVER={SQL Server};SERVER=servername;DATABASE=DBNAME;PORT=1435;PROTOCOL=TCPIP;Trusted_Connection=yes'"
SQLCA.DBParm="ConnectString='Driver={ODBC Driver 17 for SQL Server};Server=servername;Database=DBNAME;Trusted_Connection=yes;'"
SQLCA.DBParm="ConnectString='Driver={SQL Server Native Client 11.0};Server=servername;Database=DBNAME;Trusted_Connection=yes;'"
Connect using SQLCA;
You can use the reference - https://www.connectionstrings.com/microsoft-sql-server-odbc-driver/
Please make sure you are including the related DLL in the build
for SNC you need to include - pbsnc.dll for oledb- pbmsoledbsql.dll
Top comments (0)