• 大小: 283KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-06-02
  • 语言: C#
  • 标签:

资源简介

工具:vs2012 语言:C# 内含mysql与sqlserver的数据库连接测试,与获取全部的数据库名称(献给需要的人)

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
using System.Data.SqlClient;

namespace TestDatabase
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender EventArgs e)
        {
            string message = string.Empty;
            string database = this.Database.Text;
            string ip = this.Ip.Text;
            string username = this.UserName.Text;
            string password = this.PassWord.Text;
            string databasename = this.DBs.Text;
            if (string.IsNullOrEmpty(database) || string.IsNullOrEmpty(ip) || string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(databasename))
            {
                MessageBox.Show(“请检查是否有空值“);
                return;
            }
            if (this.Database.SelectedIndex == 0)
            {
                message = MySQLServer.getmysqlcon(ip username password databasename);
            }
            else if (this.Database.SelectedIndex == 1)
            {
                message = SQLServer.getsqlservercon(ip username password databasename);
            }
            else
            {
                MessageBox.Show(“请选择正确的数据库“);
                return;
            }
            MessageBox.Show(message);
        }

        private void textdb_Click(object sender EventArgs e)
        {
            string message = string.Empty;
            string database = this.Database.Text;
            string ip = this.Ip.Text;
            string username = this.UserName.Text;
            string password = this.PassWord.Text;
            string databasename = this.DatabaseName.Text;
            this.DBs.Items.Clear();
            if (this.Database.SelectedIndex == 0)
            {
                //message = MySQLServer.getmysqlcon(ip username password “test“);
                MySqlDataReader dataread = MySQLServer.exectcommad(ip username password);
                if (dataread != null)
                {
                    MessageBox.Show(“测试连接成功,请选择数据库!“);
                    while (dataread.Read())
                    {
                        this.DBs.Items.Add(dataread.GetString(0));
                    }
                }
                else
                {
                    MessageBox.Show(“连接失败!“);
                }
            }
            else if (this.Database.SelectedIndex == 1)
            {
                //message = SQLServer.getsqlservercon(ip username password “master“);
                SqlDataReader dataread = SQLServer.ExectSqlCommand(ip username password);
                if (dataread != null)
                {
              

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2017-09-20 08:38  TestDatabase\
     文件         187  2016-01-16 14:27  TestDatabase\App.config
     文件       10517  2017-07-12 15:14  TestDatabase\Form1.Designer.cs
     文件        4047  2017-07-12 15:15  TestDatabase\Form1.cs
     文件        5817  2017-07-12 15:14  TestDatabase\Form1.resx
     文件        2130  2016-01-20 14:56  TestDatabase\MySQLServer.cs
     文件         524  2016-01-16 14:27  TestDatabase\Program.cs
     目录           0  2017-09-20 08:38  TestDatabase\Properties\
     文件        1362  2016-01-16 14:27  TestDatabase\Properties\AssemblyInfo.cs
     文件        2876  2016-01-16 14:27  TestDatabase\Properties\Resources.Designer.cs
     文件        5612  2016-01-16 14:27  TestDatabase\Properties\Resources.resx
     文件        1099  2016-01-16 14:27  TestDatabase\Properties\Settings.Designer.cs
     文件         249  2016-01-16 14:27  TestDatabase\Properties\Settings.settings
     文件        1987  2017-07-12 11:03  TestDatabase\SQLServer.cs
     文件        4464  2016-01-19 15:34  TestDatabase\TestDatabase.csproj
     目录           0  2017-09-20 08:38  TestDatabase\bin\
     目录           0  2017-09-20 08:38  TestDatabase\bin\Debug\
     文件      230912  2015-09-29 14:42  TestDatabase\bin\Debug\MySql.Data.Entity.dll
     文件       14848  2019-01-22 13:43  TestDatabase\bin\Debug\TestDatabase.exe
     文件         187  2016-01-16 14:27  TestDatabase\bin\Debug\TestDatabase.exe.config
     文件       58880  2019-01-22 13:43  TestDatabase\bin\Debug\TestDatabase.pdb
     文件       22984  2019-01-22 13:44  TestDatabase\bin\Debug\TestDatabase.vshost.exe
     文件         187  2016-01-16 14:27  TestDatabase\bin\Debug\TestDatabase.vshost.exe.config
     文件         490  2015-11-13 10:24  TestDatabase\bin\Debug\TestDatabase.vshost.exe.manifest
     文件      175487  2016-01-16 17:39  TestDatabase\bin\Debug.zip
     目录           0  2017-09-20 08:38  TestDatabase\obj\
     目录           0  2019-01-22 13:43  TestDatabase\obj\Debug\
     文件        1451  2018-01-23 18:58  TestDatabase\obj\Debug\DesignTimeResolveAssemblyReferences.cache
     文件        7168  2019-01-22 13:43  TestDatabase\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
     目录           0  2019-01-22 13:44  TestDatabase\obj\Debug\TempPE\
     文件           0  2016-01-16 14:27  TestDatabase\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
............此处省略11个文件信息

评论

共有 条评论

相关资源