任何人都可以帮助SQL Connector [英] Can anyone help with SQL Connector

查看:75
本文介绍了任何人都可以帮助SQL Connector的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





大家好



我想做一个SQL我的应用程序的连接器表格



这是表格的代码:





Hi guys

I want to make a SQL Connector form for my application

this is the code for the form:

Imports System.Data.SqlClient

Public Class frmServer
    Public connectionstring As String

    Private Sub frmServer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click
        clsMSSQL.Database = txtDatabase.Text
        clsMSSQL.Server = txtServer.Text
        clsMSSQL.con.Open()
        Me.Close()
        frmMain.Show()
    End Sub

    Private Sub cmdCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCancel.Click
        Close()
    End Sub

    Private Sub cmdTest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdTest.Click
        Try
            If txtServer.Text = "" OrElse txtDatabase.Text = "" Then
                MessageBox.Show("Fill all the required fields", "SQL Connector", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            Else
                clsMSSQL.Database = txtDatabase.Text
                clsMSSQL.Server = txtServer.Text
                clsMSSQL.con.Open()
                clsMSSQL.con.Close()
                MessageBox.Show("Test Connection Successfully!")
            End If
        Catch
            MessageBox.Show("Cannot Established Connection", "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        End Try
    End Sub



和这是班级:




and this is the class:

Imports System.Data.SqlClient

Public Class clsMSSQL
    Public Shared Server As String = ""
    Public Shared Database As String = ""
    Public Shared constring As String = "Data Source=" & Server & ";Initial Catalog=" & Database & " ;Integrated Security=True;"
    Public Shared con As New SqlConnection(constring)
    Public Shared Connector As New frmServer()
End Class





这段代码哪里出错了?

我无法连接数据库而导致连接错误。



Where is the wrong in this code?
I can''t connect with database it gives connection error.

推荐答案

服务器和数据库都是空白的,因此constring将不正确 - 它是数据源=;初始目录=;集成安全性=真;



您的class clsMSSQL构造糟糕。请尝试以下代码



The Server and Database are both blank so constring will not be correct - it''s "Data Source=;Initial Catalog= ;Integrated Security=True;"

Your class clsMSSQL is badly constructed. Try the following instead

Imports System.Data.SqlClient
Public Class clsMSSQL
	Private _Server As String
	Private _Database As String
	Public Property Server() As String
		Get
			Return _Server
		End Get
		Set(ByVal value As String)
			_Server = value
		End Set
	End Property
	Public Property Database() As String
		Get
			Return _Database
		End Get
		Set(ByVal value As String)
			_Database = value
		End Set
	End Property
	Public ReadOnly Property constring() As String
		Get
			Return "Data Source=" & _Server & ";Initial Catalog=" & _Database & " ;Integrated Security=True;"
		End Get
	End Property
End Class





等等...我还没有包括你需要以类似方式改变的其他位



Etc ... I haven''t included the other bits you will need to change in a similar way


这篇关于任何人都可以帮助SQL Connector的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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