Question I am using VB2019 I want to create a database, I got problems

Mannyso

New member
Joined
Dec 26, 2023
Messages
2
Programming Experience
Beginner
I got these errors and I do not know what it is.

Exception thrown: 'System.NotImplementedException' in Appoinments.dll
'Appoinments.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.17\System.Diagnostics.StackTrace.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Appoinments.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.17\System.Reflection.Metadata.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Appoinments.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.17\System.IO.FileSystem.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Appoinments.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.17\System.Collections.Immutable.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Appoinments.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.17\System.Text.Encoding.Extensions.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
The program '[16696] Appoinments.exe' has exited with code -1 (0xffffffff).

here is my code:

VB.NET:
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()>
Partial Class Form1
    Inherits System.Windows.Forms.Form

    'Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()>
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer



    Friend WithEvents Button1 As Button

    Private Sub Form1_Load(sender As Object, e As EventArgs)

    End Sub

    'Private Sub Button1_Click(sender As Object, e As EventArgs)
    'Imports System.Data.SqlClient



    Private Sub btnCreateDatabase_Click(ByVal sender As System.Object,
        ByVal e As System.EventArgs) Handles Button1.Click
        Dim str As String





        Dim myConn As SqlConnection = New SqlConnection("Server=(local)\netsdk;" &
                                                    "uid=sa;pwd=;database=master")

        str = "CREATE DATABASE MyDatabase ON PRIMARY " &
          "(NAME = MyDatabase_Data, " &
          " FILENAME = 'C:\Appoinment\Appoinments.mdf', " &
          " SIZE = 2MB, " &
          " MAXSIZE = 10MB, " &
          " FILEGROWTH = 10%) " &
          " LOG ON " &
          "(NAME = MyDatabase_Log, " &
          " FILENAME = 'C:\Appoinment\Appoinments.ldf', " &
          " SIZE = 1MB, " &
          " MAXSIZE = 5MB, " &
          " FILEGROWTH = 10%) "

        Dim myCommand As SqlCommand = New SqlCommand(str, myConn)

        Try
            myConn.Open()
            myCommand.ExecuteNonQuery()
            MessageBox.Show("Database is created successfully",
                        "MyProgram", MessageBoxButtons.OK,
                         MessageBoxIcon.Information)
        Catch ex As Exception
            MessageBox.Show(ex.ToString())
        Finally
            If (myConn.State = ConnectionState.Open) Then
                myConn.Close()
            End If
        End Try

    End Sub


    Private Sub InitializeComponent()
        Me.Button1 = New System.Windows.Forms.Button()
        Me.SuspendLayout()
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(316, 139)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(239, 69)
        Me.Button1.TabIndex = 0
        Me.Button1.Text = "Create Database"
        Me.Button1.UseVisualStyleBackColor = True
        '
        'Form1
        '
        Me.BackColor = System.Drawing.SystemColors.InactiveCaption
        Me.ClientSize = New System.Drawing.Size(642, 378)
        Me.Controls.Add(Me.Button1)
        Me.Font = New System.Drawing.Font("Segoe UI", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point)
        Me.ForeColor = System.Drawing.SystemColors.HotTrack
        Me.Name = "Form1"
        Me.Text = "Create Database"
        Me.ResumeLayout(False)

    End Sub

    Private Sub Form1_Load_1(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub
End Class

T^hank you in advance, please I need help in this small project
 
Last edited by a moderator:
Firstly, please don't post unformatted code snippets. They are too hard to read. I have fixed the formatting for you this time. Please format your code yourself in future.

Secondly, why do you have code you've written yourself in the designer code file? That file exists specifically so that the designer code can be kept separate to the code that you write. I don't know what the hell you've done but you should get that user code out of the designer code file and put it in the user code file. If you need to create a new form to do that, that's what you should do.

Finally, with regards to the exception, a NotImplementedException is usually something that code throws specifically because a method is called that has not yet been implemented. It's safer to do this:
VB.NET:
Private Sub SomeMethod()
    Throw New NotImplementedException
End Sub
than this:
VB.NET:
Private Sub SomeMethod()

End Sub
because the former will be obvious during your testing if you call that method while the latter may go unnoticed. There are certain VS tools that will create code like that automatically and that is probably what has happened here. You should use the Find in Files feature to search for "NotImplementedException" in your code and you'll probably find the culprit. Of course, if you run the app in the debugger then VS should show you exactly where the exception is thrown. That's what debugging is for.
 
Back
Top