Subscribe Bookmark RSS Feed

Connect to SQL databse programmatically

guy_yosef

Community Trekker

Joined:

Jul 16, 2014

I made  Add In that create data base connection

but trying to retrive the data using diffrent scripts / add in does not work

do i need to creata data base connection on every add in?

this is my connection add in script

New Window("USER ID and pass", <<Modal, Text Box("insert user ID"), variablebox1 = Text Edit Box(),Text Box("insert password"), variablebox2 = Text Edit Box(<<Password Style));
userID = variablebox1 <<get text ; 
pass = variablebox2 <<get text ;  


abc = Create Database Connection("DSN=DB;UID="||userID||";PWD="||pass||";MODE=SHARE;DBALIAS=DB;");

but whenever i try to use the abc connection from diffrent add in / script it doest find it

Name Unresolved: dbc in access or evaluation of 'dbc' , dbc

dt = Execute SQL(
dbc/*###*/, ...

1 REPLY
pmroz

Super User

Joined:

Jun 23, 2011

Sounds like a scoping problem.  Make the connection variable a global variable by prefacing it with "::".

::abc  = Create Database Connection( "DSN=DB;UID=" || userID || ";PWD=" || pass || ";MODE=SHARE;DBALIAS=DB;" );