❔ 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
I try to learn every day new things..
What do you mean by "my app doesn't run"?
doesn't open
I can't debug
I can't to anything
freez
freeze*
and if you set a breakpoint on the
con.Open
line
actually, the problem is that you are doing this in your constructorif I put a comentary on con.Open it runs
thats a terrible idea
I don't know where to put it
it's my first time when I create a db
that's the error
well that error is pretty clear
it says it cant establish a connection, because your instance name is invalid
i made a method for my conn
and I open it in that method
and now runs:)
but
now
sounds like you didn't run the method :p
:p
yea
..
I would highly suggest moving away from
LocalDB
thou
sqlite is an excellent database and very good for beginners, as its file basedyea I know but I have this thing for school
so you literally have a single file with your app that contains the database, but otherwise behaves like a full SQL database
and I can't move away for LocalDb
rip
for my personal apps
I will do in sqlite
I would run it on the forms
Load
eventyea yea
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
Sorry, no idea about local db
Maybe try clearing that MDF file?
thanks
and creating a new one?
with another name?
¯\_(ツ)_/¯
As said, I don't know how it works at all
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.