Deploy VB.NET 2010 with a SQLEXPRESS .mdf file already created

Answered Deploy VB.NET 2010 with a SQLEXPRESS .mdf file already created

  • miércoles, 25 de abril de 2012 19:55
     
     

    Hello,

    I have a VB.NET 2010 application that I created.  In this application I created a database, mdf, that utilizes MSSQLEXPRESS.  When I created the setup and deployment package, I made sure that the SQL Express 2008 was a prerequisite.  I create the package, made sure that my already created mdf database was in the package and great.  It installs SQL Express 2008 if it does not exist.  It installs my application and puts the mdf database in the proper directory. 

    Then I run the program.  It loads the data properly, but when I change a record, an error comes up stating that the database is READ ONLY.  I have searched high and low for resolve and cannot find an answer.  Could someone help please.

    Thank you in advance.

Todas las respuestas

  • jueves, 26 de abril de 2012 4:41
     
     

    and puts the mdf database in the proper directory.

    Hello,

    And into what directory; in the DATA subfolder of the SQL Server installation or into your app folder?

    If the database is read only, then may because the SQL Server service account do have only read permission on that folder you used.


    Olaf Helper
    * cogito ergo sum * errare humanum est * quote erat demonstrandum *
    Wenn ich denke, ist das ein Fehler und das beweise ich täglich
    Blog Xing

  • jueves, 26 de abril de 2012 10:44
     
      Tiene código

    Hi Olaf,

    During the installation of the app, the mdf file gets installed to

    =|DataDirectory|\Data\myDB.mdf

    It does not appear that the folder has any restrictions on it. How would I make it read write during the installation of the program

    The app. Certainly we wouldn't want the end user to mess with the permissions.

    Thank you again.

  • jueves, 26 de abril de 2012 10:57
     
     

    Hello,

    How do the rest of the connection string look like, is there a "UserInstance" parameter included?


    Olaf Helper
    * cogito ergo sum * errare humanum est * quote erat demonstrandum *
    Wenn ich denke, ist das ein Fehler und das beweise ich täglich
    Blog Xing

  • lunes, 30 de abril de 2012 13:07
     
     

    Hello,

    This is the connection string that Visual Studio made:

    Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Data\SkySkor.mdf;Integrated Security=True;User Instance=False

    It connects fine on my development laptop, but as soon after I create a setup and deployment project and install it on another machine it installs the program, but then gives me an error stating that the database is READONLY.

  • lunes, 30 de abril de 2012 16:22
     
     

    Hello,

    As I expected you run it as User Instance and if the database file is located in your application then the SQL Server service account do have only read permissions, therefore your db is read only.


    Olaf Helper
    * cogito ergo sum * errare humanum est * quote erat demonstrandum *
    Wenn ich denke, ist das ein Fehler und das beweise ich täglich
    Blog Xing


  • lunes, 30 de abril de 2012 17:21
     
     

    Hi,

    Could you tell me how you would recommend fixing the solution.  When the end user installs my program, I want my program to access this database freely without going in and setting permissions.  Should I set User Instance = True in the connection string?

  • martes, 01 de mayo de 2012 16:00
     
     

    Hi,

    Could you tell me how you would recommend fixing the solution.  When the end user installs my program, I want my program to access this database freely without going in and setting permissions.  Should I set User Instance = True in the connection string?

    Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Data\SkySkor.mdf;Integrated Security=True;User Instance=False

    how are you copying the .MDF to the directory "|DataDirectory|\Data" ?

    could you check that the service account - you're not using a user instance - for SQL Server Express does have permission to the directory specified by "|DataDirectory|\Data" and that it does the permission to read and write SkySkor.mdf and SkySkor.ldf ? you've copied SkySkor.ldf too I hope?

    I you set "user Instance=true" the SQL Server Express will running within the security context of the application and than you may able to read/write the database depending on the security settings of the folder and the files - as such it's effectively the same security issue as using standard SQL Server Express.

    In addition, "user instance" feature is deprecated and will no longer be supported in the next version of SQL Server Express as it is effectively replaced by LocalDB (with other challenges)


    Please use Mark as Answer if my post solved your problem and use Vote As Helpful if a post was useful.


  • martes, 01 de mayo de 2012 18:26
     
     

    Hi Daniel,

    During the installation of the program it automatically installs the .MDF to the directory [DataDirectory]\Data

    Is there a way somehow that during the installation it will automatically make this directory Read Write so that the end user only has to install my program and start using it.  I did another test of the installation on a different machine and I noticed that the \Data folder's permissions had the Attributes check box, "Read-only (Only applies to files in folder)" check box filled in solid.

    Should I set the UserInstance to true or should I leave it like it was which was false?

    Thank you

  • martes, 01 de mayo de 2012 18:49
     
     

    Hi Daniel,

    During the installation of the program it automatically installs the .MDF to the directory [DataDirectory]\Data

    Is there a way somehow that during the installation it will automatically make this directory Read Write so that the end user only has to install my program and start using it.  I did another test of the installation on a different machine and I noticed that the \Data folder's permissions had the Attributes check box, "Read-only (Only applies to files in folder)" check box filled in solid.

    Should I set the UserInstance to true or should I leave it like it was which was false?

    setting user instance=true or not depends whether the database is shared by multiple users on the same computers, whether remote connections should be supported and where the DataDirectory is.

    if it is guarantied that the current user has full permission on DataDirectory than it User Instance may be a possible solution but as soon you aren't sure about the permission than you get the same problems.

    Please check with your current installation if the SQL Server Express service account does have read/write/modify permission on the data folder and the skyskor.mdf & .ldf (property page, effective permissions). Temporarily you can give the account full control and try it again.

    Did you check that .MDF does not have readonly file attribute set after installation ?


    Please use Mark as Answer if my post solved your problem and use Vote As Helpful if a post was useful.

  • miércoles, 02 de mayo de 2012 19:14
    Moderador
     
     Respondida

    Hello,

    Is the install done thru a dvd/cd ? If yes , the files are copied with the same attributes than on the dvd : read-only.

    In your installer, you have to include the modification of the attributes.

    Other solution which will do to shout everybody : during the install, after having installed SQL Server Express, with sqlcmd , connect to the SQL Server Express and execute a script creating your database. In this script , you may include a call to BCP to load initial data in the tables of your database. But this method is relevant from Getting Started With SQL Server or Tansact-SQL Forums ( a moderator will move your thread after you have posted your agreement ).

    A last remark : SQL Server Express 2012 will be the last version supporting the User Instance feature as it will be replaced by LocalDB. For more explanations, see http://blogs.msdn.com/b/sqlexpress/ which is the official blog of the Microsoft SQL Server Express Product Team.

    User instance has many defaults which could be unpleasant , like the difficulties to do a backup/restore of the database or the impossibility to connect from a remote computer .

    Don't hesitate to post again for more help or explanations

    Have a nice day


    Mark Post as helpful if it provides any help.Otherwise,leave it as it is.

  • viernes, 04 de mayo de 2012 10:48
     
     

    hi could you ask this on the below forum. It may help you.

    http://go4answers.webhost4life.com/Example/c-database-mdf-already-exists-75616.aspx