Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7653357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:00:48+00:00 2026-05-31T12:00:48+00:00

I have created my first project in C# which uses sql server database (file

  • 0

I have created my first project in C# which uses sql server database (file name: printing.mdf)
I have created a database on Sql Server Express and developed an application to manipulate that database.
After deploying (installing sql server on the client’s pc, then attaching database manually) everything works fine.

Real problem is that I want

  1. My application should install sql server automatically during installation.
  2. Database (printing.mfd) file should also be attached in installation process.
  3. MOST IMPORTANT: I want to save mdf file on D: drive, so that when system drive (C:) is formatted for any reason, my database should not lost.

For last problem I have tried this connection string

Data Source=.\SQLEXPRESS;AttachDbFileName=d:\printingData\printing.mdf;Integrated Security=True;User Instance=True

I also copied printing.mdf to d:\printingData
This worked on my pc but not on clients pc

Any suggestions specially related to 3rd one.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T12:00:50+00:00Added an answer on May 31, 2026 at 12:00 pm
    1. You can’t install SQL Server automatically. Even if this were possible, it would be highly UN-recommended as lots of system tests/configurations are done during the install.

    2. You can attach database files to an existing SQL Server instance at install-time using a custom installation package. NSIS is the best freeware I have come across for installation and it is very well documented and supported (by the users etc.). The functionality you want for database attachment is one of the plugins found here on the NSIS Wiki pages

    3. Of course the D: partition you may have on your PC may not exist on another user own machine. Also, there is not way of automatically creating such a partition on a user’s machine. To do, or attempt to do this would be very intrusive.

    In my opinion, I would create some documentation specifying the recommended configuration for your software. You could also provide the installation instructions documenting how to partition the hard drive. But you will find that users (casual users esp.) will not want to be doing such things!

    Edit: To answer your comment. For installation from the command prompt in see the following MSDN article – good luck, and be carefull attempting to automate this, it is NOT a good idea…

    To attach a database using TSQL use the following queries:

    -- For an .mdf with no log file - rebuild it.
    CREATE DATABASE [{0}] ON ( FILENAME = N'{1}' ) ATTACH_REBUILD_LOG;);     
    -- For a standard attach.
    CREATE DATABASE [{0}] ON ( FILENAME = N'{1}' ) FOR ATTACH;
    

    Note you can use a system stored proceedure to attach databases but this is being phased out by Microsoft.

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a file argument.pl which takes several arguments first of which should
I have my first CQRS project which uses event sourcing and I was wondering
I am trying to write my first WCF project. I have created a project
I have a big project that was first created in Borland C++ 6. We're
I have created a project which consist of a tabbarcontroller and a navigationcontroller .
I have created a a subclass of Table in my ASP.NET project which creates.
Help me, please, solve one problem. I have project, which uses Nhibernate and Fluent
First some context: I have an MVC3 .net project which, for the sake of
I have created a Silverlight project which also contains a Web project. I have
Let me first describe my goal: I have created an object with 3 properties:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.