posh studio EXE gets an ODBC connection error

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
User avatar
fvenezia65
Posts: 8
Last visit: Tue Nov 30, 2021 12:32 pm

Re: posh studio EXE gets an ODBC connection error

Post by fvenezia65 »

thank you, JVierra!
*that* was the issue.
and Happy Thanksgiving to you!

jvierra
Posts: 14986
Last visit: Tue Nov 30, 2021 9:48 pm
Answers: 15
Has voted: 3 times
Been upvoted: 12 times

Re: posh studio EXE gets an ODBC connection error

Post by jvierra »

I was pretty sure that was the issue as it is quite common. See "help about scopes" to understand how "scope" is implemented in PowerShell.

And Happy Thanksgiving to you too. Watch out for the cranberries...they can be a challenge.

Observe the following: https://www.youtube.com/watch?v=8MuhFxaT7zo

User avatar
fvenezia65
Posts: 8
Last visit: Tue Nov 30, 2021 12:32 pm

Re: posh studio EXE gets an ODBC connection error

Post by fvenezia65 »

wondering if putting the function in a .PSM1 might make it work.
going to try tomorrow.
thanks again!
-frank

jvierra
Posts: 14986
Last visit: Tue Nov 30, 2021 9:48 pm
Answers: 15
Has voted: 3 times
Been upvoted: 12 times

Re: posh studio EXE gets an ODBC connection error

Post by jvierra »

See "help about scopes"

It doesn't matter where you put it, the object has to be "in scope". and object declared in a module or function will dispapear from all scopes when the function exits. It is better to vae a function that returns a connection object or, better, a function that returns a DataTable object and releases the connection and other objects. Now scope is no longer a barrier to acquiring a data object.

Best you learn PowerShell first then you will understand that PowerShell is an object system and not a batch scripting language or an old language like "Basic". We have abandoned those old things more than 20 years ago.

PowerShell can be used as a batch scripting system but as soon as you do more than list independent commands then all bets are off the table and you will get lost in a second.

Reading the help on scopes will solve that issue and the help is built-in and should be your first place to understand commands, tokens, syntax, grammar and behaviors. Once you get the flavor of a modern coded system then the rest will become so easy that you will wonder why you started by trying to just copy and guess.

Good luck, have fun and break through the mental barriers that all of us have difficulties breaking through.

Post Reply