Sign in to follow this  
Followers 0
JeromeB

SQL connection and informations

11 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



There is a available that should do what you need.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Yep, i saw this UDf, but can you give me an example with what i need to do ?

mu informations ?

Thx

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

$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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

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

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Thanks for the SQL UDF here gos my contribution for the SQL_UDF.au3

Getting TABLE NAME From the Data BASE

New Function _SQL_GetTableName() for SQL

Moved to:

Edited by Elias

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

SQL GUI using "_sql.au3"

Moved to:

Edited by Elias

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0