C
C#13mo ago
Rugjrh

❔ DataBaseProblem

Hi Guys! I have this code when I try to make my db connection: SqlConnection con; public MainForm() { InitializeComponent(); con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True"); con.Open(); } But my app doesn't run. What's the problem? I'm a beginner in SQL.
28 Replies
Rugjrh
RugjrhOP13mo ago
I try to learn every day new things..
Pobiega
Pobiega13mo ago
What do you mean by "my app doesn't run"?
Rugjrh
RugjrhOP13mo ago
doesn't open I can't debug I can't to anything freez freeze*
Pobiega
Pobiega13mo ago
and if you set a breakpoint on the con.Open line actually, the problem is that you are doing this in your constructor
Rugjrh
RugjrhOP13mo ago
if I put a comentary on con.Open it runs
Pobiega
Pobiega13mo ago
thats a terrible idea
Rugjrh
RugjrhOP13mo ago
I don't know where to put it it's my first time when I create a db
Rugjrh
RugjrhOP13mo ago
No description
Rugjrh
RugjrhOP13mo ago
that's the error
Pobiega
Pobiega13mo ago
well that error is pretty clear it says it cant establish a connection, because your instance name is invalid
Rugjrh
RugjrhOP13mo ago
i made a method for my conn and I open it in that method and now runs:) but now
Rugjrh
RugjrhOP13mo ago
No description
Pobiega
Pobiega13mo ago
sounds like you didn't run the method :p
Rugjrh
RugjrhOP13mo ago
:p yea ..
Pobiega
Pobiega13mo ago
I would highly suggest moving away from LocalDB thou sqlite is an excellent database and very good for beginners, as its file based
Rugjrh
RugjrhOP13mo ago
yea I know but I have this thing for school
Pobiega
Pobiega13mo ago
so you literally have a single file with your app that contains the database, but otherwise behaves like a full SQL database
Rugjrh
RugjrhOP13mo ago
and I can't move away for LocalDb
Pobiega
Pobiega13mo ago
rip
Rugjrh
RugjrhOP13mo ago
for my personal apps I will do in sqlite
Pobiega
Pobiega13mo ago
I would run it on the forms Load event
Rugjrh
RugjrhOP13mo ago
yea yea
Rugjrh
RugjrhOP13mo ago
No description
Rugjrh
RugjrhOP13mo ago
how do I remove the databse with same name? or what's the problem here? @Pobiega , sorry for @ you, but can u help me? I'm so freaked up with these things, because no one can help me... my teachers are useless
Pobiega
Pobiega13mo ago
Sorry, no idea about local db Maybe try clearing that MDF file?
Rugjrh
RugjrhOP13mo ago
thanks and creating a new one? with another name?
Pobiega
Pobiega13mo ago
¯\_(ツ)_/¯ As said, I don't know how it works at all
Accord
Accord13mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server