none
visual basic With Data Base Problem RRS feed

  • Question

  • How to Fix database read Only In VB after installing on me PC ?

    my Directory path in Visual Studio 2017  community version source\repos\Local Data Base\Local Data Base\bin\Debug.

    in Debug Folder Contains  one Db Folder And Four Files > localDb.exe , LocalDb(XML Configuration ) , LocalDb.pdb and localDb(Xml Document)

    Add database Directory path IS source\repos\Local Data Base\Local Data Base\bin\Debug\Db\Test1.mdf

    How To Fix  Read only Error In VB 


    • Edited by A.SaadS Sunday, August 25, 2019 4:56 AM
    Sunday, August 25, 2019 4:54 AM

All replies

  • Hello,

    • Provide the exact error message
    • From Windows Explorer select the database right click, check if read-only attribute is checked if so un-check.
    • Unsure no other program has the database open 
    • Try placing the database under C:\Users\user name\AppData
    • Provide the connection string

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Sunday, August 25, 2019 11:11 AM
    Moderator
  • This is Exact Error when Inserting  data into Database .

    Title OF Error Message Dialog  Property Management System 

    Unhandled Exception has Occurred in your Application . if Click Continue ,the Application  will ignore this Error and attempt To Continue. if you click Quit , the Application Will Close immediately.

    attempt to Write a read-only database .

    attempt to Write a read-only database .

    =======================================

    I am a Student Of BCA  AND working on A database project for learning its types Application.

      • I already un-check to database Property of read-only .
      •  yes I Sure to no other program has the database open.
      • "Try placing the database under C:\Users\user name\AppData" . you mean database Move to root Directory To other  folder   Like us AppData.
        
    • Connection String in Xml   <connectionStrings>
          <add name="dbx"
               connectionString="Data Source=(LocalDB)\v11.0;
               AttachDbFilename='|DataDirectory|\db\Test.mdf';
               Integrated Security=True;" providerName="System.Data.SqlClient"/>
        </connectionStrings>

    Connection String In VB 

    Imports System.Data.SqlClient
    Imports System.Configuration
    Public Class Form1
        Dim MyConnectionString As New SqlConnection("Data Source=(LocalDB)\v11.0;")
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            If MyConnectionString.State = ConnectionState.Closed Then
                MyConnectionString.Open()
            ElseIf MyConnectionString.State = ConnectionState.Broken Then
                MyConnectionString.Open()
            Else
                MessageBox.Show("Connection Are is closed", "Conn Failed")
            End If
            DataGridView1.DataSource = myData()

        End Sub

        Private Function myData() As DataTable

            Dim dt As New DataTable
            Try
            'Connection String
                Dim connectionString As String = ConfigurationManager.ConnectionStrings("dbx").ConnectionString
                Using sqlconnection As New SqlConnection(connectionString)
                    Using selectCommand As New SqlCommand("select * from Info", sqlconnection)
                        sqlconnection.Open()
                        Using datareader As SqlDataReader = selectCommand.ExecuteReader()
                            dt.Load(datareader)
                        End Using
                    End Using
                End Using
                'datareader.Close()
            Catch ex As ApplicationException
                MessageBox.Show(ex.Message, "Error")
            End Try
            Return dt
        End Function
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Try
            'Connection String
                Dim connectionString As String = ConfigurationManager.ConnectionStrings("dbx").ConnectionString
                Using sqlconnection As New SqlConnection(connectionString)
                    Using selectCommand As New SqlCommand("insert into Info (Name, Mobile, Email) values(@Name, @Mobile, @Email)", sqlconnection)
                        sqlconnection.Open()
                        selectCommand.Parameters.AddWithValue("@Name", TextBox1.Text)
                        selectCommand.Parameters.AddWithValue("@Mobile", TextBox2.Text)
                        selectCommand.Parameters.AddWithValue("@Email", TextBox3.Text)
                        selectCommand.ExecuteNonQuery()
                    End Using
                End Using
                MessageBox.Show("Data added Succesfully", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information)
                myData()
            Catch ex As ApplicationException
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try
        End Sub

    End Class

    here Not use any Class and Extension from NuGet.what Errors I My Code ?


    Wednesday, September 4, 2019 3:26 PM
  • Hi,

    I tested your code, but it showed that everything was working, and the results were shown in the following figure.

    You can see your database attributes, right-click -> Properties -> Options -> Status, which has the item "Database read-only" as True, please change it to False.

      <connectionStrings>
        <add name="dbx"
             connectionString="Data Source = (localdb)\MSSQLLocalDB; Integrated Security = True ;AttachDbFileName= D:\Local Database\190905.mdf"/>
      </connectionStrings>


    Imports System.Data.SqlClient
    Imports System.Configuration
    Public Class Form1
        Dim MyConnectionString As New SqlConnection("Data Source = (localdb)\MSSQLLocalDB;")
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            If MyConnectionString.State = ConnectionState.Closed Then
                MyConnectionString.Open()
            ElseIf MyConnectionString.State = ConnectionState.Broken Then
                MyConnectionString.Open()
            Else
                MessageBox.Show("Connection Are is closed", "Conn Failed")
            End If
            DataGridView1.DataSource = myData()
        End Sub
    
        Private Function myData() As DataTable
    
            Dim dt As New DataTable
            Try
                'Connection String
                Dim connectionString As String = ConfigurationManager.ConnectionStrings("dbx").ConnectionString
                Using sqlconnection As New SqlConnection(connectionString)
                    Using selectCommand As New SqlCommand("select * from Info", sqlconnection)
                        sqlconnection.Open()
                        Using datareader As SqlDataReader = selectCommand.ExecuteReader()
                            dt.Load(datareader)
                        End Using
                    End Using
                End Using
                'datareader.Close()
            Catch ex As ApplicationException
                MessageBox.Show(ex.Message, "Error")
            End Try
            Return dt
        End Function
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Try
                'Connection String
                Dim connectionString As String = ConfigurationManager.ConnectionStrings("dbx").ConnectionString
                Using sqlconnection As New SqlConnection(connectionString)
                    Using selectCommand As New SqlCommand("insert into Info (Name, Mobile, Email) values(@Name, @Mobile, @Email)", sqlconnection)
                        sqlconnection.Open()
                        selectCommand.Parameters.AddWithValue("@Name", TextBox1.Text)
                        selectCommand.Parameters.AddWithValue("@Mobile", TextBox2.Text)
                        selectCommand.Parameters.AddWithValue("@Email", TextBox3.Text)
                        selectCommand.ExecuteNonQuery()
                    End Using
                End Using
                MessageBox.Show("Data added Succesfully", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information)
                myData()
            Catch ex As ApplicationException
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try
        End Sub
    End Class

    Hope I can help you.

    Best regards,

    Julie


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Thursday, September 5, 2019 4:31 AM
  • Can its Work on other PC when only Installed SqlLocalDb .
    Thursday, September 5, 2019 3:11 PM
  • Hi,

    It should be that the account you use to operate the database does not have permission to modify the database. You can try this modification by adding "Authenticated Users" to the directory of the files where the database files are located, and giving full operational authority to solve the problem. In addition, you can try the modification method of "Local Database Problem" in this link.

    Hope I can help you.

    Best Regards,

    Julie


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, September 6, 2019 6:15 AM
  •  I have done Database grid property to database-Read-Only = false .

    where to found property of second  image in SQL On visual Studio   ?

    I want to auto Add Permission for All User with root Directory and not store Any Data in  any Directory like us : AppData.

    if its not possible to auto add Permission to database then How to Microsoft activate database in all Windows system.


    • Edited by A.SaadS Friday, September 6, 2019 10:36 AM
    Friday, September 6, 2019 10:26 AM
  • Hi,

    Have you solved this problem now?
    If so, hope you can close this thread by marking the reply as answer as this will help others looking for the same or similar issues down the road.

    As for other questions, I hope you can open a new threading.

    In addition, you can see your database attributes on the right of visual Studio, right-click -> Properties -> Options -> Status.

    Hope I can help you.

    Best Regards,

    Julie


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, September 9, 2019 5:49 AM
  • this folder not show in my visual studio under of server explorer. I used to serviced based Database. I think its  cause to nit show Database Folder in server Explorer. I when create setup  file of its solution so its store all Data in program folder and then install setup  on virtual machine  and other computer then error message given to Database Read-only .after installation  setup file I right click -> database folder and file property -> attributes ->  uncheck -> ok  and add gives permission Everyone user with Full Control but all remove automatically .

    i thik why not move database File to move other derive  like us : D ,E  with Folder and program leave in root Directory. 

    Monday, September 9, 2019 6:52 PM
  • Hi,

    You can open and configure Object Explorer through this.

    Do you resolve the issue? If you resolve the issue, please mark the helpful as answer. It will be beneficial to other community.

    Best Regards,

    Julie


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, September 12, 2019 7:29 AM
  • Why can't you put the MDF file in the C:\programdata folder an 'All Users folder' and point to the file in the localDB connectionstring?
    • Edited by DA924x Thursday, September 12, 2019 7:51 AM
    Thursday, September 12, 2019 7:50 AM
  • Hi 

    when I put my mdf In to C:\ProgramData Folder an 'User Folder' and to the File in local DB connectionString . but not inserted data when check this File on my VM(Virtual Machine) and given Error to  ->

    Unhandled Exception has Occurred in your Application . if Click Continue ,the Application  will ignore this Error and attempt To Continue. if you click Quit , the Application Will Close immediately.

    attempt to Write a read-only database .

    how to fix dear . in this stage .

    I right click -> database folder and file property -> attributes ->  uncheck -> ok  and add gives permission Everyone user with Full Control but all remove automatically .

    Friday, September 13, 2019 12:19 PM
  • Hi

    Try using a User folder to hold the DB file(s), such as Documents or a subfolder within.


    Regards Les, Livingston, Scotland

    Friday, September 13, 2019 12:24 PM
  • How did you create this MDF file? Did you use Visual Studio Service Based Database feature? Have you tried to write to the MDF file by using VS ,,Server Explorer to access the MDF file or used SSMS to access the MDF file? How did the MDF file even windup in a Bin folder when you first started developing against?

    And do things work without the VM being involved?

    • Edited by DA924x Friday, September 13, 2019 5:23 PM
    Friday, September 13, 2019 5:09 PM
  • MDF file Created through Visual Studio.

    Yes I use Visual Studio Service based Database Feature.

    I Follow This step for Local Db  .

    • create a form  
    • set property 
    • add A folder In solution explorer with dB Name folder
    • then add A service based database feature file with Custom name in  dB folder  
    • after Create file then double Click .MDf file 
    • after opening file in Server Explorer then right Click and Select add new Table 
    • after Create table put few data manually and then call in form1
    • after code to form1 and app.config file then run application in debug mode
    • here inserted Data in Database in my laptop 

    but after Setup file making  not inserted data On My Virtual machine only Given Error attempt  write Database  to Read-Only Database . how fix it . 

    Saturday, September 14, 2019 7:04 AM
  • This thread looks as from somebody who is tossing for an reply as "You did nothing wrong, it is probably a bug".  You give no reply to the suggestions which have done and what was then the result. 

    I don't know who started by using the name "service based database", but it confuses. 

    You use in my perception a local SQL database file. Not a file integrated in SQL server. 

    Nevertheless, for both needs SQL server to be running (or reachable) on the platform where your program runs. 

    Your database file needs to be located in a read-write enabled folder. That is if you are using an OS newer than W8, not the program files folder and not the C:\ root folder. (You can use as Les wrote the document folder to try or as Julie has shown a new folder). 



    Success
    Cor


    • Edited by Cor Ligthert Saturday, September 14, 2019 8:57 AM
    Saturday, September 14, 2019 8:56 AM
  • The problem clearly is with this VM thing. What is this VM thing some kind of 3rd party software? The creation of the MDF file using Visual Studio''s Service Based Database feature and your subsequent usage of the MDF file in write mode seems to be fine. The problems start for you where the MDF file is in some read only state only manifests itself when this VM comes into plsy.

     

     

     

     

    Saturday, September 14, 2019 12:35 PM
  • If Problem only With VM So Why not Run on any other computer .

    When run only Through By debug And release folder  why ? 

    can you tell how to full  file in write mode  with Step by a step. 

    then i check  my step and file  to write mode or not .

    Saturday, September 14, 2019 2:13 PM
  • dear Cor lighter  "You give no reply to the suggestions which have done and what was then the result. " its your text .  so I tell you now I doing step those suggestion in form and reply My problem if any see . I think you understand ?  
    Saturday, September 14, 2019 2:22 PM
  • MDF file Created through Visual Studio.

    Yes I use Visual Studio Service based Database Feature.

    I Follow This step for Local Db  .

    • create a form  
    • set property 
    • add A folder In solution explorer with dB Name folder
    • then add A service based database feature file with Custom name in  dB folder  
    • after Create file then double Click .MDf file 
    • after opening file in Server Explorer then right Click and Select add new Table 
    • after Create table put few data manually and then call in form1
    • after code to form1 and app.config file then run application in debug mode
    • here inserted Data in Database in my laptop 

    but after Setup file making  not inserted data On My Virtual machine only Given Error attempt  write Database  to Read-Only Database . how fix it . 

    Sounds like a non-code issue but permissions to the folder where the database resides. Refactor code to run off a non virtual machine and see what happens. Also, place the database in the same folder as the executable for now along with running on a non virtual folder.

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Saturday, September 14, 2019 2:30 PM
    Moderator
  • Do you know how to check and set NTFS user account permissions on a folder or file in the folder?
    Saturday, September 14, 2019 7:15 PM
  • I Creating Setup With " Inno Setup " with These Step>

    • Open Inno Setup 
    • Click New For New setup Wizard
    • Then Click Next
    • Appearing new form in front      And Filling Application Name And Some info Click Next
    • Appearing new form in front      And asked To Program Folder i Given Name To TestApp
    • Appearing new form in front      its Time Asking to Main Executable File  so I gived 
    • And Default Enabled to Those Button  1) Add  File .  2) Add Folder.
    • Click To Add File  then Browse To Configuration File in release And select to Configuration file 
    • Then Add Folder from Release Folder To Db Folder (Database Folder ).
    • Then Click To Next
    • Then  Again Click To Next 
    • Then  Again Click To Next 
    • Select Languages And Click To Next
    • Select Folder For Compiler Output.
    • and Enter Setup Base name
    • Then Click next 
    • Then Click next
    • Click Finish
    • Show popup Message and click To NO for Edit To  DataBase Folder Right Path  just Like as Debug/Release Foldder .
    • " DestDir: "{app}\db " Here add \db  after Compile and Run 
    • after install application in pc or  other pc same as debug/ Release Folder.
    Wednesday, September 18, 2019 2:57 PM
  • You have some kind of user permissions issue that may be at the folder level you are deploying the MDF file in or the file itself may have user permissions issues. Just because you unchecked the read only property does it mean that permission on the folder or file is set correctly for a folder or file in a folder to be accessable for read and write.

    NTFS is the part of the Windows O/S the controls user access to a folder or file in a folder.

    www.varonis.com/blog/ntfs-permissions-vs-share

    So find out what your logged on user account permissions are on the MDF file after you deploy the solution to a computer. All Windows desktop programs run under the context of the logged in user account and the rights the user account has to work with resources controlled by the O/S.

    Wednesday, September 18, 2019 10:22 PM
  • I  doing same step already. if any solution my problem so tell . 
    Friday, September 20, 2019 2:45 PM
  • I  doing same step already. if any solution my problem so tell . 

    https://social.msdn.microsoft.com/Forums/sqlserver/en-US/home?forum=sqlexpress

    Maybe, someone in the forum can help you.

    Saturday, September 21, 2019 8:27 AM