C
C#2y 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
RugjrhOP2y ago
I try to learn every day new things..
Pobiega
Pobiega2y ago
What do you mean by "my app doesn't run"?
Rugjrh
RugjrhOP2y ago
doesn't open I can't debug I can't to anything freez freeze*
Pobiega
Pobiega2y 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
RugjrhOP2y ago
if I put a comentary on con.Open it runs
Pobiega
Pobiega2y ago
thats a terrible idea
Rugjrh
RugjrhOP2y ago
I don't know where to put it it's my first time when I create a db
Rugjrh
RugjrhOP2y ago
No description
Rugjrh
RugjrhOP2y ago
that's the error
Pobiega
Pobiega2y ago
well that error is pretty clear it says it cant establish a connection, because your instance name is invalid
Rugjrh
RugjrhOP2y ago
i made a method for my conn and I open it in that method and now runs:) but now
Rugjrh
RugjrhOP2y ago
No description
Pobiega
Pobiega2y ago
sounds like you didn't run the method :p
Rugjrh
RugjrhOP2y ago
:p yea ..
Pobiega
Pobiega2y 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
RugjrhOP2y ago
yea I know but I have this thing for school
Pobiega
Pobiega2y ago
so you literally have a single file with your app that contains the database, but otherwise behaves like a full SQL database
Rugjrh
RugjrhOP2y ago
and I can't move away for LocalDb
Pobiega
Pobiega2y ago
rip
Rugjrh
RugjrhOP2y ago
for my personal apps I will do in sqlite
Pobiega
Pobiega2y ago
I would run it on the forms Load event
Rugjrh
RugjrhOP2y ago
yea yea
Rugjrh
RugjrhOP2y ago
No description
Rugjrh
RugjrhOP2y 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
Pobiega2y ago
Sorry, no idea about local db Maybe try clearing that MDF file?
Rugjrh
RugjrhOP2y ago
thanks and creating a new one? with another name?
Pobiega
Pobiega2y ago
¯\_(ツ)_/¯ As said, I don't know how it works at all
Accord
Accord2y 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.

Did you find this page helpful?