当前位置: 首页 > news >正文

C# 创建Oceanbase ODBC数据源 DSN

需要管理员权限打开VS,因为只有管理员权限可以修改注册表

using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.Odbc;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;namespace WindowsFormsApp1
{public partial class Form1 : Form{public Form1(){InitializeComponent();}private void button1_Click(object sender, EventArgs e){//Process install = new Process();//ProcessStartInfo processStart = new ProcessStartInfo();processStart.WorkingDirectory = @"D:\ESPT_Release\";//processStart.Arguments = @"/i D:\ESPT_Release\ob-connector-odbc-2.0.8.2-win32.msi  /q";//processStart.FileName = "msiexec";processStart.Verb = "runas";//install.StartInfo = processStart;//install.Start();//install.WaitForExit();string ODBC_PATH = "SOFTWARE\\ODBC\\ODBC.INI\\";string driverName = "OceanBase ODBC 2.0 Driver";string dsnName = "OceanbaseC#";string database = "aaa";string description = "This DSN was created from code!";string server = "10.00.0.1";string port = "2883";bool trustedConnection = true;// Lookup driver path from driver name //C:\\Program Files (x86)\\OceanBase\\OceanBase ODBC Driver\\obodbc.dllstring driverPath = "OceanBase ODBC 2.0 Driver";var datasourcesKey = Registry.LocalMachine.CreateSubKey(ODBC_PATH + "ODBC Data Sources");if (datasourcesKey == null){throw new Exception("ODBC Registry key does not exist");}datasourcesKey.SetValue(dsnName, driverName);// Create new key in odbc.ini with dsn name and add values        var dsnKey = Registry.LocalMachine.CreateSubKey(ODBC_PATH + dsnName);if (dsnKey == null){throw new Exception("ODBC Registry key for DSN was not created");}dsnKey.SetValue("Database", database);dsnKey.SetValue("Description", description);dsnKey.SetValue("Driver", driverPath);dsnKey.SetValue("TCPIP", 1);//dsnKey.SetValue("LastUser", "YMS");dsnKey.SetValue("Server", server);dsnKey.SetValue("Port", port);dsnKey.SetValue("Database", database);//dsnKey.SetValue("user name", "YMS@obpoc#obdemo");dsnKey.SetValue("UID", "aaa@obpoc#obdemo");//dsnKey.SetValue("user name", "YMS@obpoc#obdemo");dsnKey.SetValue("password", "bbb");dsnKey.SetValue("QUERYTIMEOUT", "10800");dsnKey.SetValue("READTIMEOUT", "3600");dsnKey.SetValue("WRITETIMEOUT", "3600");dsnKey.SetValue("Trusted_Connection", trustedConnection ? "Yes" : "No");//DataTable dt = new DataTable();//string dns = "Dsn=OceanbaseC#;uid=YMS@obpoc#obdemo";//string sql = @"SELECT * from ESPT_ACE_BIN_GROUP where rownum < 10";//OdbcConnection conn = new OdbcConnection(dns);OdbcCommand cmd = new OdbcCommand(sql, conn);//conn.Open();//OdbcDataAdapter adapter = new OdbcDataAdapter(sql, conn);//adapter.Fill(dt);//this.dataGridView1.DataSource = dt;//this.dataGridView1.Show();}}
}
http://www.lryc.cn/news/212353.html

相关文章:

  • C++ 常用函数汇总#include<algorithm>(3万字总结)
  • Google Archive Patch 基础应用代码记录
  • 机器学习——代价敏感错误率与代价曲线
  • 如何利用 ChatGPT 提升编程技能
  • ChatGPT:@EqualsAndHashCode(callSuper = false)是什么意思
  • docker部署的mariadb忘记密码
  • 一体化模型图像去雨+图像去噪+图像去模糊(图像处理-图像复原-代码+部署运行教程)
  • [java/力扣110]平衡二叉树——优化前后的两种方法
  • 吉他、班卓琴和贝斯吉他降分器:Arobas Music Guitar 8.1.1
  • cocos tilemap的setTileGIDAt方法不实时更新
  • 机器学习---使用 TensorFlow 构建神经网络模型预测波士顿房价和鸢尾花数据集分类
  • 铁合金电炉功率因数补偿装置设计
  • 表格识别软件:科技革新引领行业先锋,颠覆性发展前景广阔
  • 【Redis】高并发分布式结构服务器
  • 微信小程序拍照页面自定义demo
  • 单目标应用:进化场优化算法(Evolutionary Field Optimization,EFO)求解微电网优化MATLAB
  • 推荐算法面试
  • 长图切图怎么切
  • 动手学深度学习 - 学习环境配置
  • 洛谷 B2004 对齐输出 C++代码
  • seccomp学习 (1)
  • Linux指令【上】
  • RK3568-clock
  • 新恶意软件使用 MSIX 软件包来感染 Windows
  • 干货!数字IC后端入门学习笔记
  • 力扣:144. 二叉树的前序遍历(Python3)
  • 【数据挖掘 | 数据预处理】缺失值处理 重复值处理 文本处理 确定不来看看?
  • 二叉树问题——前/中/后/层遍历(递归与栈)
  • Nor Flash和Nand Flash的区别——笔记
  • 7+共病思路。WGCNA+多机器学习+实验简单验证,易操作