|Accueil → WINDEV 22 → WD21 : How to connect with MS SQL database over the network?|
|WD21 : How to connect with MS SQL database over the network?|
|Débuté par Joris, 16 mai 2017 15:49 - 6 réponses|
Posté le 16 mai 2017 - 15:49
I need to make a connection with an SQL database to load some data from another software into our Windev application (that is using Hyperfile).
I managed to do this by using the SQLConnect() command, SQLFirst(), SQLNext() etc...
This is working fine on the server (where the SQL database is located) but not on workstations.
I'm using this command :
MyConnection is int = SQLConnect("SBS2011\PFD","MyLogin","MyPassword","PFD","OLEDB",hOledbSQLServer)
SQL Server 2008 R2
SBS2011 is the name of the server
PFD is the name of the database
Posté le 16 mai 2017 - 16:08
I'ld use oleDB for SQL Server in this case instead of ODBC...
You'll make your life a lot easier.
Posté le 16 mai 2017 - 16:38
is 1433 port open on your SBS2011 ??
Posté le 16 mai 2017 - 16:45
- In SQL server manager allow remote connections
- In SQL configuration manager allow the tcp-ip protocol instead of pipes
- SQL express uses dynamic ports. Google for configure firewall mssql express.
Posté le 18 mai 2017 - 15:30
I could connect to any MS Sql Server in my network with the following connection parameters.
DataBaseConnection is Connection
DataBaseConnection..Provider = hOledbSQLServer
DataBaseConnection..User = INIRead("Database","LogId", "", "INI FileName")
DataBaseConnection..Password = INIRead("Database", "Logpassword","", "INI FileName")
DataBaseConnection..Server = INIRead("Database", "ServerName","", "INI FileName")
DataBaseConnection..Database = INIRead("Database", "Database", "", "INI FileName")
//DataBaseConnection..Access = hORead
IF HOpenConnection(DataBaseConnection) = False THEN
IF HChangeConnection("*", DataBaseConnection) = False THEN
Hope by having relevant data in the ini file, you could also connect.
Posté le 22 mai 2017 - 11:37
Thank you both for your answers. I am able to connect with the server and get some data with the code below.
MyConnection is Connection MyQuery is Data Source MyConnection..Provider = hOledbSQLServer MyConnection..User = "MyLogin" MyConnection..Password = "MyPassword" MyConnection..Server = "SBS2011\PFD" MyConnection..Database = "PFD" MyConnection..Access = hORead IF NOT HOpenConnection(MyConnection) THEN Error("The connection to the data source failed." + CR + HErrorInfo(hErrFullDetails)) RETURN END IF NOT HExecuteSQLQuery(MyQuery,MyConnection,hQueryWithoutCorrection,"select DESCRIPTION from TR031") THEN Error(HErrorInfo) RETURN END FOR ALL MyQuery Trace(MyQuery.DESCRIPTION) END HCloseConnection(MyConnection)
Posté le 22 mai 2017 - 19:58
I created a little application using hyperfile to store my SQL server DB connections info in (and to encrypt them) and also used this to create a menu system to allow me to pick which DB to mount to.