Results 1 to 8 of 8

Thread: [RESOLVED] Give myself permission to access a sql database I created through a vb.net program?

Threaded View

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2021
    Posts
    26

    Resolved [RESOLVED] Give myself permission to access a sql database I created through a vb.net program?

    I am trying to create a sql database, and table, programmatically with vb.net. The database gets created OK but when it tries to create the table, I get the following exception error:

    System.Data.SqlClient.SqlException
    HResult=0x80131904
    Message=The specified schema name "MoviePlot" either does not exist or you do not have permission to use it.
    Source=.Net SqlClient Data Provider

    MSSMS shows the database exists, but there is no table.

    I plagiarized from one of the forums and used the following code changing only the filenames and table criteria. The program creates the database on my computer of which I am the administrator. How do I change the security criteria when I create the database so it will create the table? Better question, why do I have to?

    My version:
    Code:
    Imports System.Data.SqlClient
    Public Class Form1
        Private Sub CreateDatabase_Load(sender As Object, e As EventArgs) Handles 
             MyBase.Load
        End Sub
    
        Private Sub BtnCreateDatabase_Click(sender As Object, e As EventArgs) 
            Handles btnCreateDatabase.Click
            Dim Conn As New SqlConnection("Data Source=DESKTOP- 
                H7RL6S9\SQLEXPRESS;Initial Catalog=master;Integrated 
                  Security=True")
            Dim Text1 As String = "I:\Developement\CreateDatabase"
            Dim Text2 As String = "MoviePlot"
            Using Conn
                Conn.Open()
                Dim cmd As SqlCommand = Conn.CreateCommand
                Dim str As String = "CREATE Database {0} ON (Name= N'{0}', 
                    FileName='{1}\{0}.mdf')"
                Dim Tbl As String = "CREATE TABLE MoviePlot.MyPlots (Title 
                   NVARCHAR(150) NOT NULL Primary Key, Plot NVARCHAR(750)  NULL)"
    
                cmd.CommandText = String.Format(str, Text2, Text1)
                cmd.ExecuteNonQuery()
                MessageBox.Show("Database is created successfully",
            "MyProgram", MessageBoxButtons.OK,
            MessageBoxIcon.Information)
    
                cmd.CommandText = String.Format(Tbl)
                cmd.ExecuteNonQuery()
                MessageBox.Show("Table is created successfully",
                 "MyProgram", MessageBoxButtons.OK,
                 MessageBoxIcon.Information)
            End Using
    
        End Sub
    
    End Class
    Last edited by Shaggy Hiker; Jan 22nd, 2022 at 07:52 PM. Reason: Added CODE Tags.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width