Click here to Skip to main content
15,896,154 members

Run time from VB.NET (no error)

Computechsoft asked:

Open original thread
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
Tags: Visual Basic

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900