Rss & SiteMap

Foxtable(狐表) http://www.foxtable.com

新一代数据库软件,完美融合Access、Foxpro、Excel、vb.net之优势,人人都能掌握的快速软件开发工具!
共18 条记录, 每页显示 10 条, 页签: [1] [2]
[浏览完整版]

标题:VB.NET如何转狐表?

1楼
lgz518 发表于:2024/9/27 9:42:00
Imports MySql.Data.MySqlClient
Imports Newtonsoft.Json
Imports System.IO
 
Module Module1
    Sub Main()
        '
        Dim config As String = File.ReadAllText("config.json")
        Dim configData As ConfigData = JsonConvert.DeserializeObject(Of ConfigData)(config)
        Dim connStr As String = $"serve-r={configData.server};user={configData.user};password={configData.password};database={configData.database}"
        Using conn As New MySqlConnection(connStr)
            conn.Open()
            Dim backupSql As String = "BACKUP DATABASE your_database TO DISK = 'AA.sql'"
            Using cmd As New MySqlCommand(backupSql, conn)
                cmd.ExecuteNonQuery()
            End Using

        End Using
    End Sub
 
    Public Class ConfigData
        Public Property server As String
        Public Property user As String
        Public Property password As String
        Public Property database As String
    End Class
 
End Module
2楼
有点蓝 发表于:2024/9/27 10:17:00
全局代码
    Public Class ConfigData
        Public Property server As String
        Public Property user As String
        Public Property password As String
        Public Property database As String
    End Class

按钮
        Dim config As String = Filesys.ReadAllText("config.json")
        Dim configData As ConfigData = Newtonsoft.Json.JsonConvert.DeserializeObject(Of ConfigData)(config)
        Dim connStr As String = cexp("serve-r={0};user={1};password={2};database={3}",configData.server,configData.user,configData.password,configData.database)
        Using conn As New MySql.Data.MySqlClient.MySqlConnection(connStr)
            conn.Open()
            Dim backupSql As String = "BACKUP DATABASE your_database TO DISK = 'AA.sql'"
            Using cmd As New MySql.Data.MySqlClient.MySqlCommand(backupSql, conn)
                cmd.ExecuteNonQuery()
            End Using

        End Using
3楼
lgz518 发表于:2024/9/27 13:30:00
按键代码
Dim config As String = Filesys.ReadAllText("config.json")
Dim configData As ConfigData = Newtonsoft.Json.JsonConvert.DeserializeObject(Of ConfigData)(config)
Dim connStr As String = cexp("serve-r={0};user={1};password={2};database={3}", configData.server, configData.user, configData.password, configData.database)
Using conn As New MySql.Data.MySqlClient.MySqlConnection(connStr)
    conn.Open()
Dim backupSql As String = "BACKUP DATABASE your_database TO DISK = 'D:\BF\t03-2024-9-27.sql'"
    Using cmd As New MySql.Data.MySqlClient.MySqlCommand(backupSql, conn)
        cmd.ExecuteNonQuery()
    End Using
    
End Using

报错:
Authentication to host '' for user '' using method 'mysql_native_password' failed with message: Access denied for user ''@'fe80::3bb8:b5f1:fce2:6b0b%5' (using password: NO)

说明:config.json是MYSQL加密的连配置

问题一:上面报错是不是config.json有加密,这里没解密?还是没有指定config.json的文件指定的路径?如何解决?

问题二:上面如何加下面异常代码,进行异常处理?


Try 
'        proc.Start() 
'        proc.StandardInput.Flush() 
'        proc.StandardInput.Close() 
          
'        ' 等待进程执行完成  
'        proc.WaitForExit() 
          
'        ' 检查退出代码以确认是否成功  
'        If proc.ExitCode <> 0 Then 
'            MessageBox.Show("备份失败,请检查错误输出。") 
'        Else 
'            MessageBox.Show("备份成功!") 
'        End If 
'    Catch ex As Exception 
'        MessageBox.Show("备份过程中发生错误: " & ex.Message) 
'    End Try 
[此贴子已经被作者于2024/9/27 13:30:22编辑过]
4楼
有点蓝 发表于:2024/9/27 13:42:00
1、1楼提供的代码里没有解密的用法
2、参考:http://www.foxtable.com/webhelp/topics/2070.htm
[此贴子已经被作者于2024/9/27 13:42:23编辑过]
5楼
lgz518 发表于:2024/9/27 14:10:00
1、1楼提供的代码里没有解密的用法
报错:
Authentication to host '' for user '' using method 'mysql_native_password' failed with message: Access denied for user ''@'fe80::3bb8:b5f1:fce2:6b0b%5' (using password: NO)

说明:config.json是MYSQL加密的连配置与不加密的连配置都一样上面报错,如何解决?
6楼
有点蓝 发表于:2024/9/27 14:13:00
和代码无关。提示用户或者密码错误,无法连接数据库
7楼
lgz518 发表于:2024/9/27 14:23:00
config.json与狐表能正常连接,上面的代码怎么连连不到?是上面代码读不了config.json的文件?如何解决?
8楼
有点蓝 发表于:2024/9/27 14:33:00
config.json里面是什么内容?
9楼
lgz518 发表于:2024/9/27 14:59:00
1.调试:
Dim connStr As String = cexp("serve-r={0};user={1};password={2};database={3}", configData.server, configData.user, configData.password, configData.database)
msgbox(connStr) '调试用



Using conn As New MySql.Data.MySqlClient.MySqlConnection(connStr)
 msgbox(3) '调试用
    conn.Open()
    msgbox(4) '调试用

报错:
Authentication to host '' for user '' using method 'mysql_native_password' failed with message: Access denied for user ''@'fe80::3bb8:b5f1:fce2:6b0b%5' (using password: NO)

10楼
lgz518 发表于:2024/9/27 14:59:00
2.
2.1config.json无加密
{
  "dbSettings": {
    "defaultConnection": "ts",//
    "connectionStrings": [
      {
       "name": "ts",
        "type": "mysql",
            
      "connectionString": "serve-r=127.0.0.1;user id=MYSQL;password=123456;database=ts;sslmode=none"

  },
}
}
}
2.1config.json加密
   2.2
{
  "dbSettings": {
    "defaultConnection": "ts",//
    "connectionStrings": [
      {
       "name": "ts",
        "type": "mysql",
            
      "connectionString": "serve-r=加密;sslmode=none"

  },
}
}
}
共18 条记录, 每页显示 10 条, 页签: [1] [2]

Copyright © 2000 - 2018 foxtable.com Tel: 4000-810-820 粤ICP备11091905号

Powered By Dvbbs Version 8.3.0
Processed in .02930 s, 2 queries.