Click here to Skip to main content
14,297,581 members
Rate this:
Please Sign up or sign in to vote.
See more:
Run time from my vb.net application (No Error) Run sucsessfully.
When i build and install software Error display 

Two connection string Frist line connection is uncomment line.
<pre>Cannot open database "TestScript" requested by then logn.
The login faild
Login failded for user 'Computech-PC\Computech'


second connection is comment line.
but error same

Two connection string Frist line connection is uncomment line.
<pre>Cannot open database "TestScript" requested by then logn.
The login faild
Login failded for user 'Administrator'


What I have tried:

Imports System.Configuration
Imports System.Data.SqlClient
Imports System.IO

Public Class FrmComputechTechnology

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
          CmdRefresh.Enabled = False
        PictureComputech.SizeMode = PictureBoxSizeMode.CenterImage
        'Me.Icon = Global.RMS.My.Resources.RabtayIco
        Me.Icon = Global.WindowsApplication1.My.Resources.RMSIcon

        Dim SQLConnectionString As String = "Data Source=Computech-PC\SQLEXPRESS;Initial Catalog=Master;Integrated Security=true;User ID=sa;Password=", providerName1 = "System.Data.SqlClient"
        'Dim SQLConnectionString As String = "Data Source=Computech-PC\SQLEXPRESS;Initial Catalog=Master;User ID=Administrator;Password=Admin", providerName1 = "System.Data.SqlClient"

        PictureComputech.Image = Global.WindowsApplication1.My.Resources.ComputechTechnology

        Using SqlCon As SqlConnection = New SqlConnection(SQLConnectionString)

            Dim StrDatabase As String

            Dim CreateDirectory As DirectoryInfo = Directory.CreateDirectory(Application.StartupPath & "\Computech")  'Product_Picture.Image.Save(PicturePath & "\" & PicturefileNameonly,

            ' "Data Source=" & Application.StartupPath & "\" &
            Dim ComputechDataBaseMDB As String = "Computech.mdf"
            Dim ComputechDataBaseLOG As String = "Computech.log"

            StrDatabase = "CREATE DATABASE TestScript ON PRIMARY (NAME = SQLSqript_Data, FILENAME = '" & Application.StartupPath & "\Computech\" & ComputechDataBaseMDB & "', " & _
           " SIZE = 2MB, MAXSIZE = 10MB, FILEGROWTH = 10%) LOG ON(NAME = SQLSqript_Log, FILENAME = '" & Application.StartupPath & "\Computech\" & ComputechDataBaseLOG & "'," & _
           " SIZE = 1MB,MAXSIZE = 5MB, FILEGROWTH = 10%) "

            Dim cmd As SqlCommand = New SqlCommand(StrDatabase, SqlCon)
            Try
                cmd.Connection.Open()
                cmd.ExecuteNonQuery()
                cmd.Connection.Close()
                SqlCon.Close()
            Catch
                MsgBox("Tow record already exist, delete and refresh to continue :", MsgBoxStyle.Critical, Title:="Computech Technology")
            End Try
        End Using

        Dim SQLConnectionStringTeble As String = "Data Source=Computech-PC\SQLEXPRESS;Initial Catalog=TestScript;Integrated Security=true;User ID=sa;Password=", providerName = "System.Data.SqlClient"
        'Dim SQLConnectionStringTeble As String = "Data Source=Computech-PC\SQLEXPRESS;Initial Catalog=TestScript;User ID=Administrator;Password=Admin", providerName = "System.Data.SqlClient"

        Using SqlConTable As SqlConnection = New SqlConnection(SQLConnectionStringTeble)

            Try
                Dim StrTable As String

                StrTable = "CREATE TABLE [dbo].[Script]([Name] [nvarchar](50) NULL,[Address] [nvarchar](50) NULL,[Phone] [nvarchar](50) NULL) ON [PRIMARY]"
                Dim cmdTable As SqlCommand = New SqlCommand(StrTable, SqlConTable)

                cmdTable.Connection.Open()
                cmdTable.ExecuteNonQuery()
                'cmdTable.Connection.Close()

                '**************************** Insert record in script table *************************************
                Dim First_Query As New SqlCommand("INSERT [dbo].[Script] ([Name], [Address], [Phone]) VALUES (N'Andreson', N'Australia', N'1231321020')", SqlConTable)
                First_Query.ExecuteNonQuery()

                Dim Second_Query As New SqlCommand("INSERT [dbo].[Script] ([Name], [Address], [Phone]) VALUES (N'Nandrason', N'Australia', N'1231321020')", SqlConTable)
                Second_Query.ExecuteNonQuery()
                '**************************** Insert process complete *******************************************


                Dim Check_User_Name_Found As New SqlClient.SqlCommand("Select Max(Name) from TestScript.dbo.Script", SqlConTable)
                Dim Check_UserNameFound = Check_User_Name_Found.ExecuteScalar().ToString()

                Dim ds_Product_Items = New DataSet
                Dim tables = ds_Product_Items.Tables

                Dim da_Product_Items = New SqlClient.SqlDataAdapter("Select Name,Address,Phone from TestScript.dbo.Script order by Name", SqlConTable)
                da_Product_Items.Fill(ds_Product_Items, "Script")

                Dim view As New DataView(tables(0))
                DataGridView1.DataSource = view

                DataGridView1.AllowUserToAddRows = False
                DataGridView1.ReadOnly = True
                DataGridView1.Rows(0).Cells(0).Selected = False
                SqlConTable.Close()

            Catch
                'MsgBox(" Already installed database", MsgBoxStyle.Critical)
            End Try
        End Using

    End Sub

    Private Sub DataGridView1_CellFormatting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles DataGridView1.CellFormatting
        DataGridView1.Item(e.ColumnIndex, e.RowIndex).ToolTipText = "These rows has been freeze"
    End Sub

    Private Sub CmdRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdRefresh.Click
        CmdDelete.Enabled = True
        CmdRefresh.Enabled = False
        Dim SQLConnectionStringTeble As String = "Data Source=Computech-PC\SQLEXPRESS;Initial Catalog=TestScript;Integrated Security=true;User ID=sa;Password=", providerName = "System.Data.SqlClient"
        'Dim SQLConnectionStringTeble As String = "Data Source=Computech-PC\SQLEXPRESS;Initial Catalog=TestScript;User ID=Administrator;Password=Admin", providerName = "System.Data.SqlClient"

        Using SqlConTable As SqlConnection = New SqlConnection(SQLConnectionStringTeble)

            '**************************** Insert record in script table *************************************
            SqlConTable.Open()
            Dim First_Query As New SqlCommand("INSERT [dbo].[Script] ([Name], [Address], [Phone]) VALUES (N'Andreson', N'Australia', N'1231321020')", SqlConTable)
            First_Query.ExecuteNonQuery()

            Dim Second_Query As New SqlCommand("INSERT [dbo].[Script] ([Name], [Address], [Phone]) VALUES (N'Nandrason', N'Australia', N'1231321020')", SqlConTable)
            Second_Query.ExecuteNonQuery()
            '**************************** Insert process complete *******************************************

            'SqlConTable.Open()

            Dim Check_User_Name_Found As New SqlClient.SqlCommand("Select Max(Name) from TestScript.dbo.Script", SqlConTable)
            Dim Check_UserNameFound = Check_User_Name_Found.ExecuteScalar().ToString()

            Dim ds_Product_Items = New DataSet
            Dim tables = ds_Product_Items.Tables

            Dim da_Product_Items = New SqlClient.SqlDataAdapter("Select Name,Address,Phone from TestScript.dbo.Script order by Name", SqlConTable)
            da_Product_Items.Fill(ds_Product_Items, "Script")

            Dim view As New DataView(tables(0))
            DataGridView1.DataSource = view

            DataGridView1.AllowUserToAddRows = False
            DataGridView1.ReadOnly = True
            DataGridView1.Rows(0).Cells(0).Selected = False
            SqlConTable.Close()

        End Using
    End Sub

    Private Sub CmdDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdDelete.Click
        CmdRefresh.Enabled = True
        CmdDelete.Enabled = False
        DataGridView1.DataSource = Nothing
        Dim SQLConnectionStringTeble As String = "Data Source=Computech-PC\SQLEXPRESS;Initial Catalog=TestScript;Integrated Security=true;User ID=sa;Password=", providerName = "System.Data.SqlClient"
        'Dim SQLConnectionStringTeble As String = "Data Source=Computech-PC\SQLEXPRESS;Initial Catalog=TestScript;User ID=Administrator;Password=Admin", providerName = "System.Data.SqlClient"

        Using SqlConTable As SqlConnection = New SqlConnection(SQLConnectionStringTeble)
            SqlConTable.Open()
            Dim DeleteAndRefresh As New SqlCommand("Delete from TestScript.dbo.Script", SqlConTable)
            DeleteAndRefresh.ExecuteNonQuery()
        End Using

    End Sub

    Private Sub CmdDelete_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles CmdDelete.MouseHover
        CmdDelete.ForeColor = Color.Fuchsia
    End Sub

    Private Sub CmdDelete_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles CmdDelete.MouseLeave
        CmdDelete.ForeColor = Color.Black
    End Sub

    Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
        DataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect
    End Sub
End Class
Posted
Updated 21-Sep-18 21:11pm
v2

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Read the error message:
Cannot open database "TestScript" requested by then logn.
The login faild
Login failded for user 'Administrator'
The login failed. You need to find out what the right login details for your system are, and we can;t tell you that - we don;t know. But you very certainly shouldn't be trying to use "sa" and particularly not with a blank password!

Come on, you've been working on this for long enough - you should know this stuff by now! And if you don't, you seriously need to study it before you start trying to throw together code and hope it works.
   
Comments
Computechsoft 22-Sep-18 4:05am
   
Sorry ? This error message on this connection this is Administrator Connection

'Dim SQLConnectionString As String = "Data Source=Computech-PC\SQLEXPRESS;Initial Catalog=Master;User ID=Administrator;Password=Admin", providerName1 = "System.Data.SqlClient"
Computechsoft 22-Sep-18 4:09am
   
But this line is comment if uncomment this message display

Cannot open database "TestScript" requested by then logn.
The login faild
Login failded for user 'Administrator'

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100