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.
This topic is 2 years and 3 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
fvenezia65
Posts: 8
Last visit: Wed Feb 14, 2024 9:44 am

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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 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: Wed Feb 14, 2024 9:44 am

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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 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.
This topic is 2 years and 3 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked