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:
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