Computechsoft Ответов: 1

Время выполнения от 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'


второе соединение-это строка комментария.
но ошибка та же

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'


Что я уже пробовал:

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

1 Ответов

Рейтинг:
5

OriginalGriff

Прочтите сообщение об ошибке:

Cannot open database "TestScript" requested by then logn.
The login faild
Login failded for user 'Administrator'
Ошибка входа в систему. Вам нужно выяснить, каковы правильные регистрационные данные для вашей системы, и мы не можем вам этого сказать - мы не знаем. Но вы совершенно определенно не должны пытаться использовать "sa", и особенно не с пустым паролем!

Да ладно тебе, ты уже достаточно долго над этим работаешь - ты должен уже знать все это! И если вы этого не сделаете, вам серьезно нужно изучить его, прежде чем вы начнете пытаться собрать код и надеяться, что он работает.


Computechsoft

- Простите ? Это сообщение об ошибке в этом соединении это подключение администратора

'Дим SQLConnectionString как String = "источник данных=Computech-ПК\sqlexpress в;начальный каталог=мастер;идентификатор пользователя= "администратор"; пароль=admin", providerName1 = "системы.Данных.Поставщики sqlclient"

Computechsoft

Но эта строка является комментарием, Если раскомментировать это сообщение.

Не удается открыть базу данных "TestScript", запрошенную затем logn.
Ошибка входа в систему
Ошибка входа в систему для пользователя "администратор"