?
Solved

Can't pass connection from one form to another

Posted on 2008-06-12
1
Medium Priority
?
222 Views
Last Modified: 2013-11-26
Hi everyone,

I'm completely stuck at passing the connection info from my login form to my main form. The program should:

- Connect to the remote MySQL DB
- Fetch a list of usernames so the user select his/her
- Validate the user's password with the MD5 password stored in the DB
- If the user and password matches, show the main form
- Open the main form having the connection stablished (this is the problem)

I attached two TXT files with both forms to see if anyone can help me with this.

Thanks a lot in advanced!!
login.txt
main.txt
0
Comment
Question by:Cesar Aracena
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 9

Accepted Solution

by:
Rurne earned 2000 total points
ID: 21771756
It looks like your MySQLConnection is simply falling out of scope.   In login.txt, you define

"Public Class frmLogin
    Dim conn As MySqlConnection
    Dim myCommand As New MySqlCommand
    Dim myAdapter As New MySqlDataAdapter"


conn, myCommand, and myAdapter are thus all local properties of the frmLogin class.  As you never pass it to frmMain before calling frmMain.Show(), calling conn.Open() and conn.Close() in frmMain_Load should result in error: frmMain.conn has no parameters, as it's a completely separate MySQLConnection from frmLogin.conn.

The easiest way around this would be to define conn, not as a property of either class, but as a global MySQLConnection, which you can then reference in the appropriate namespaces.
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question