从VB.NET运行时间(没有错误) [英] Run time from VB.NET (no error)

查看:71
本文介绍了从VB.NET运行时间(没有错误)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

推荐答案

阅读错误消息:

Read the error message:
Cannot open database "TestScript" requested by then logn.
The login faild
Login failded for user 'Administrator'

登录失败。您需要找出系统的正确登录详细信息,我们可以告诉您 - 我们不知道。但是你肯定不应该尝试使用sa,特别是不要使用空白密码!



来吧,你一直在努力够 - 你现在应该知道这些东西!如果你不这样做,在你开始尝试将代码放在一起并希望它能够工作之前,你真的需要研究它。

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.


这篇关于从VB.NET运行时间(没有错误)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆