Hi
I have below code but it is not going in Load function
C#
using Sap.Data.Hana;
namespace Atulaya
{
public partial class Form1 : Form
{
HanaConnection conn;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
conn = new HanaConnection(System.Configuration.ConfigurationManager.ConnectionStrings["Hana"].ConnectionString);
conn.Open();
Console.WriteLine("Connected");
}
}
}Thanks

Amit MohantyRank #112 · 20K reputationPosted Dec 11, 2024, 1:09 AM EST
Make sure that the Form1_Load event is assigned to the form's Load event. This can be either in the designer or manually in your code. Check that, in your designer file (Form1.Designer.cs), the Load event is hooked up like this:
this.Load += new System.EventHandler(this.Form1_Load);Jayraj ChhayaRank #304 · 8.2K reputationPosted Dec 11, 2024, 5:49 AM EST
Hi Ramco,
The issue you're encountering may stem from the fact that the
Form1_Loadevent is not properly wired up to the form's Load event. To resolve this, ensure that theForm1_Loadmethod is correctly associated with the Load event of the form. You can do this in the designer or programmatically in the constructorpublic Form1() { InitializeComponent(); this.Load += new EventHandler(Form1_Load); }Additionally, ensure that your connection string in the configuration file is correctly set up and that the
Sap.Data.Hanalibrary is properly referenced in your project. If the connection fails, the message "Connected" will not be displayed.Lastly, consider using
MessageBox.Show("Connected");instead ofConsole.WriteLineto display the message in a Windows Forms application, asConsole.WriteLinemay not show output in the UI context.private void Form1_Load(object sender, EventArgs e) { conn = new HanaConnection(System.Configuration.ConfigurationManager.ConnectionStrings["Hana"].ConnectionString); conn.Open(); MessageBox.Show("Connected"); }