Jump to content

SQL connection and informations


JeromeB
 Share

Recommended Posts

Hello everyone,

A part of my script consist to get information from a database in an SQL server 2003.

If you can give me an example, i would like to get in variables information from the database "Sonde" in a servor "DS" (need to login in, so user / pass), and get back information from table "dbo.config".

If someone can give me this part of code (connection + informations), and maybe some exemple to write in a table ( SQl commande insert into...) ?

thx for helping,

Jerome

Edited by Jerome60
Link to comment
Share on other sites

There is a available that should do what you need.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Something like this:

#include <_SQL.au3>
#include <array.au3>
Global $sServer = "DS"
Global $sDB = "Sonde"
Global $sUsername = "????", $sPassword = "????"
Global $aResult, $iRows, $iColumns
$oADODBHandle = SQL_Startup()
$iReturn = _SQL_Connect($oADODBHandle, $sServer, $sDB, $sUsername, $sPassword)
_SQL_GetTable2d($oADODBHandle, "select * from dbo.config", $aResult, $iRows, $iColumns)
_ArrayDisplay($aResult)
_$iResult = _SQL_Close()

This is a very simple example and completely lags error handling. Check the returncode of each function and use function _SQL_RegisterErrorHandler to establish an error handler.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Hey,

thx for your reply, but its not working ...

==> The requested action with this object has failed.:
$ADODBHandle.Open("DRIVER={SQL Server};SERVER=" & $server & ";DATABASE=" & $db & ";uid=" & $username & ";pwd=" & $password & ";")
$ADODBHandle.Open("DRIVER={SQL Server};SERVER=" & $server & ";DATABASE=" & $db & ";uid=" & $username & ";pwd=" & $password & ";")^ ERROR

Don't know why, i put the good password and user "sa".

I think its the DRIVER the problem, but how can i know which driver do i have to put ? Refer to i got the same error code, so its the driver, but what i have to do to fix it ?

Edited by Jerome60
Link to comment
Share on other sites

$sServer = "DS" seems to be a bit short. Is this the name of the physical machine your SQL server is hosted?

Can you ping this server?

Is the Microsoft SQL driver installed on your machine? Open the command prompt and run "odbccp32.cpl" and check if a driver named "SQL Server" is available.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Server is not DS, but its ok, i didnt want to give you the name of my server, but i changed it in my script, no worry.

SQL server driver is installed on my computer, this is ok too.

And i can ping my server xD

In my SQL server, i can read : SQL Server 9.0.4035

Edited by Jerome60
Link to comment
Share on other sites

Could you please insert the following line

_SQL_RegisterErrorHandler()
into your script before line:

$oADODBHandle = SQL_Startup()

The error handler should write some useful information to the console.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • 3 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...