Connecting to Local SQLExpress Instance in VB.NET

Posted on 2009-04-17
Last Modified: 2013-11-08
I have a 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

Question by:ekenman
    LVL 31

    Expert Comment

    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.

    Author Comment

    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?
    LVL 31

    Expert Comment

    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.

    Author Comment

    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!

    Accepted Solution

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
    Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now