C
C#•9mo ago
nole19

Connection property has not been initialized

Hello, I need help, I tried to fix the problem but i am stuck
No description
14 Replies
Buddy
Buddy•9mo ago
$details
MODiX
MODiX•9mo ago
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)
Buddy
Buddy•9mo ago
Please post code 🙂
nole19
nole19OP•9mo ago
ok I am doint desktop application, jus so you know
nole19
nole19OP•9mo ago
nole19
nole19OP•9mo ago
@Citizen of Pluto
Buddy
Buddy•9mo ago
$paste
MODiX
MODiX•9mo ago
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!
Buddy
Buddy•9mo ago
I can't see the code on mobile, it prompts me to download.
nole19
nole19OP•9mo ago
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(); } } }
Buddy
Buddy•9mo ago
Are you initializing the connection property? as the error says
nole19
nole19OP•9mo ago
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(); } } }
Buddy
Buddy•9mo ago
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
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server