• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 767
  • Last Modified:

Connecting to Local SQLExpress Instance in VB.NET

I have a VB.net application with a SQL Express DB. Today I'm distributing the DB with the application. This is fine until the user wants to upgrade to a later version when my DB will replace the allready existing DB of the user (with all his data).

So I thought I'd script the DB with the values that I want in some tables if there is no database present when the user starts the app. Here is were I get into trouble. I use a connectionstring with "AttachDbFilename=|DataDirectory|dbname.mdf" How do I check if it allready exists? And what also occured to me, if the user allready have an SQL Server installed and named it other than SQLEXPRESS, how will I find it?

Anyway I would be grateful for any advice on this topic.

Best Regards

Tomas
0
ekenman
Asked:
ekenman
  • 3
  • 2
1 Solution
 
RiteshShahCommented:
you can give one .ini file in your application and tell client to update sql server's credential and name there, you can create dynamic connection string based on that. all you need to do is, read .ini file.
0
 
ekenmanAuthor Commented:
I have the app.config in my project which contains the connectionstring. I don't quite understand. How will I update the SQL Server's credential and name in the ini-file?
0
 
RiteshShahCommented:
well in your case, you can generate one class which will read .INI file, create connecting string and you can use it everywhere in your application, app.config won't help in your case, I guess.
0
 
ekenmanAuthor Commented:
Yes. My question is HOW to create the connection string though. HOW will I find out what the local instance is named. Putting the connection string together is a small matter when I figured out where to check if the DB exists.
To clarify, the user will most often have no idea of what the name of the instance is. This is for a commercial software so I won't know either.
I'll be out of office till Monday so I won't be able to give any feed back until then. Have a nice week end!
/Tomas
0
 
ekenmanAuthor Commented:
I've done som research and apparently when you publish a local database it does not overwrite the existing one for the user. This will have to do for now so I'm closing this question.
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now