Connection property has not been initialized
Hello, I need help, I tried to fix the problem but i am stuck
14 Replies
$details
When you ask a question, make sure you include as much detail as possible. Such as code, the issue you are facing, and what you expect the result to be. Upload code here https://paste.mod.gg/ (see $code for more information on how to paste your code)
Please post code 🙂
ok
I am doint desktop application, jus so you know
@Citizen of Pluto
$paste
If your code is too long, you can post to https://paste.mod.gg/ and copy the link into chat for others to see your shared code!
I can't see the code on mobile, it prompts me to download.
private void textBoxPretraziMarke_TextChanged(object sender, EventArgs e)
{
PrimeniPretragu();
}
private void NadjiModelMarke()
{
int tekuciRed = dataGridViewMarke.CurrentRow.Index;
int MarkaID = (int)dataGridViewMarke.Rows[tekuciRed].Cells[0].Value;
podaciModela.DataSource = ModelDAO.UcitajModel(MarkaID);
dataGridViewModel.DataSource = podaciModela;
}
private void dataGridViewMarke_SelectionChanged(object sender, EventArgs e)
{
NadjiModelMarke();
}
}
}
Are you initializing the connection property?
as the error says
yes
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Data.SqlClient;
using System.Configuration;
namespace AutiKlijent
{
internal class Konekcija
{
public static readonly string konekcioniString = ConfigurationManager.ConnectionStrings["AutiDB"].ConnectionString;
public static void TestKonekcije()
{
using SqlConnection konekcija = new(konekcioniString);
konekcija.Open();
}
}
}
Using implies that it is freed (disposed) when it goes out of scope. So no, you are not.
Also you are not storing the connection variable anywhere
Your method seems to just test the connection, not actually connect and be used.
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View