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

ext做的网站2023年11月新冠高峰

ext做的网站,2023年11月新冠高峰,apache做网站,做游戏课程网站提示 \color{red}{提示} 提示: 《Linux系统上编译安装FreeTDS库文件》中讲述了如何编译FreeTDS源码,并安装。 本文部分内容会在上述文章的基础上深入。 本文内容所使用的环境 Windows系统:Windows 10 企业版 64位操作系统;IP&a…

提示 \color{red}{提示} 提示
《Linux系统上编译安装FreeTDS库文件》中讲述了如何编译FreeTDS源码,并安装。

本文部分内容会在上述文章的基础上深入。

本文内容所使用的环境

  • Windows系统:Windows 10 企业版 64位操作系统;IP:192.168.1.130
  • Linux系统:BigCloud Enterprise Linux 8.2 (Core);IP:192.168.1.110
  • 数据库:Microsoft SQL Server 2008 (RTM) Enterprise Edition,安装在Windows系统上,默认端口:1433

需求背景

C# .NET8框架的程序运行在Linux系统上,使用技术手段,使得C#程序不仅可以访问Linux系统上的SQLServer数据库,也能访问Windows系统上的SQLServer数据库,以应对复杂的应用场景需求。

注:可能还有很多种方式可以实现需求,这里讲述 ODBC+FreeTDS 的方式。

思路

  • C#程序无法直接使用FreeTDS库文件,但是可以使用ODBC数据库标准接口。
  • ODBC标准接口可以指定使用FreeTDS作为数据库驱动。
  • 这样就可以使用ODBC调用FreeTDS驱动,实现数据库访问。

1.首先验证网络问题

根据文章《FreeTDS从Linux访问Windows SqlServer数据库》中说明验证就可以,这里不在累赘。

2.安装unixODBC包

yum install unixODBC

3.安装unixODBC-devel开发包(后面重新编译FreeTDS会用到)

yum install unixODBC-devel

4.重新编译安装FreeTDS

这里重新编译FreeTDS,是为了使FreeTDS支持ODBC管理,即要生成 libtdsodbc.so 驱动库,方便配置。
根据官网《How to build: Configure and make》章节介绍,在使用 configure 命令时,要加上 –with-unixodbc,才能生成 libtdsodbc.so 驱动库,使FreeTDS支持ODBC管理。

  • 参数 --with-unixodbc 使用的时候,后面跟 unixODBC-devel 开发包的安装路径,如下:

./configure --prefix=/usr/local --with-tdsver=7.4 --with-unixodbc=/usr --enable-msdblib

–with-unixodbc 参数的路径一定要写对,不然编译不过,会提示找不到sql.h文件。
配置好后就按文章《Linux系统上编译安装FreeTDS库文件》中的介绍编译安装好即可。

5.配置freetds.conf

还是采用文章《FreeTDS从Linux访问Windows SqlServer数据库》中的配置不用变

# The server you added yourself
[myWin130]host = 192.168.1.130port = 1433tds version = 7.0

6.配置odbcinst.ini

这个配置文件中,存储了ODBC驱动程序的信息,可以指定驱动程序。
在配置文件中添加如下代码:

[FreeTDS]
Description=FreeTDS Driver for Linux
Driver=/usr/local/lib/libtdsodbc.so
Setup=/usr/local/lib/libtdsodbc.so
UsageCount=1

这里,添加了一个别名为 FreeTDS 的驱动(名字可以随便起,符合实际意义就好),这个驱动的信息为:

  • Description:描述字段(随便写),符合实际情况就行
  • Driver:指定使用的驱动程序库文件的位置,这里指定freetds中的odbc驱动支持库文件。
    即上面生成的libtdsodbc.so库的位置。
  • Setup:指定了用于安装驱动程序的设置库文件位置,这里写成和驱动程序库文件一样的即可。
  • UsageCount:默认就好

7.配置odbc.ini

此文件用来配置ODBC的数据源名称,在配置文件中添加如下代码:

[win130]
Driver = FreeTDS
Servername = myWin130
Database = fy2000

解释:

    1. 配置了一个名称为 win130 的数据源(名字可以随便起,符合实际意义就行),
    1. 指定驱动为 odbcinst.ini 文件中添加的驱动 FreeTDS
    1. 指定服务器名称使用 freetds.conf 配置中的 myWin130
    1. 制动数据库名称为 fy2000

8.使用isql命令行工具访问数据库

[root@localhost ~]# isql -v win130 sa 123456
+---------------------------------------+
| Connected!                            |
|                                       |
| sql-statement                         |
| help [tablename]                      |
| echo [string]                         |
| quit                                  |
|                                       |
+---------------------------------------+
select * from tb_student_info where class>2
+----------------+------------+------------+------------+
| name           | class      | age        | hight      |
+----------------+------------+------------+------------+
| 小红            | 6          | 35         | 130        |
| 小兵            | 3          | 25         | 234        |
+----------------+------------+------------+------------+
SQLRowCount returns 2
2 rows fetched
SQL> quit
[root@localhost ~]# 

到这里配置的ODBC就起作用了。

9.C#-Demo代码

新建 test .NET8 项目,在项目中安装 System.Data.Odbc 软件包,
Program.cs 文件内容如下:

using System.Data.Odbc;string connectionString = "DSN=win130;UID=sa;PWD=123456;";
using (OdbcConnection connection = new OdbcConnection(connectionString))
{try{connection.Open();Console.WriteLine("Connection opened successfully.");// 执行 SQL 查询  string sql = "SELECT * FROM tb_student_info";OdbcCommand command = new OdbcCommand(sql, connection);using (OdbcDataReader reader = command.ExecuteReader()){while (reader.Read()){// 处理查询结果  Console.WriteLine(String.Format("{0}, {1}, {2}, {3}", reader[0], reader[1], reader[2], reader[3]));}}}catch (Exception ex){Console.WriteLine("Error: " + ex.Message);}
}

发布到Linux服务器并运行

[root@localhost test]# dotnet test.dll
Connection opened successfully.
小美, 2, 18, 123
小红, 6, 35, 130
小兵, 3, 25, 234
[root@localhost test]# 

可以看到程序运行成功。


以上就是本次分享的全部内容,希望对你有帮助,感谢您的查阅。


文章转载自:
http://dinncojackey.ssfq.cn
http://dinncohumanitarian.ssfq.cn
http://dinncodrilling.ssfq.cn
http://dinncosleepyhead.ssfq.cn
http://dinncooak.ssfq.cn
http://dinncoprecipitate.ssfq.cn
http://dinncoattrited.ssfq.cn
http://dinncospirochaetosis.ssfq.cn
http://dinncomonothematic.ssfq.cn
http://dinncopartaker.ssfq.cn
http://dinncoqkt.ssfq.cn
http://dinncocabalism.ssfq.cn
http://dinncoreascend.ssfq.cn
http://dinncocardsharp.ssfq.cn
http://dinncoerbium.ssfq.cn
http://dinncooverquantification.ssfq.cn
http://dinncoteagirl.ssfq.cn
http://dinncocrustless.ssfq.cn
http://dinncoshane.ssfq.cn
http://dinncoempathic.ssfq.cn
http://dinncolamarckian.ssfq.cn
http://dinncomatlo.ssfq.cn
http://dinncobiography.ssfq.cn
http://dinncorussianise.ssfq.cn
http://dinnconeurohypophysis.ssfq.cn
http://dinncoshould.ssfq.cn
http://dinncoforeknowledge.ssfq.cn
http://dinncooffenbach.ssfq.cn
http://dinncoaspherical.ssfq.cn
http://dinncocookhouse.ssfq.cn
http://dinncorecordmaker.ssfq.cn
http://dinncoclove.ssfq.cn
http://dinncooncidium.ssfq.cn
http://dinncosapiential.ssfq.cn
http://dinncoebu.ssfq.cn
http://dinncoantiphony.ssfq.cn
http://dinncohaemachrome.ssfq.cn
http://dinncoarchine.ssfq.cn
http://dinncocollaborationism.ssfq.cn
http://dinncobroncho.ssfq.cn
http://dinnconosey.ssfq.cn
http://dinncobeezer.ssfq.cn
http://dinncoastrosphere.ssfq.cn
http://dinncosakhalin.ssfq.cn
http://dinncohammurapi.ssfq.cn
http://dinncoquotative.ssfq.cn
http://dinncodreamt.ssfq.cn
http://dinncovic.ssfq.cn
http://dinncomaterialization.ssfq.cn
http://dinncoanywhither.ssfq.cn
http://dinncostrained.ssfq.cn
http://dinncoextramusical.ssfq.cn
http://dinncoclimatotherapy.ssfq.cn
http://dinncorecognize.ssfq.cn
http://dinncoacyl.ssfq.cn
http://dinncomutualism.ssfq.cn
http://dinncobillet.ssfq.cn
http://dinncoenglishment.ssfq.cn
http://dinncoaquaemanale.ssfq.cn
http://dinncopolycarpous.ssfq.cn
http://dinncosinarquist.ssfq.cn
http://dinncopippa.ssfq.cn
http://dinncoflotsam.ssfq.cn
http://dinncosublease.ssfq.cn
http://dinncoxanthomatosis.ssfq.cn
http://dinncoironworks.ssfq.cn
http://dinncohomoecious.ssfq.cn
http://dinncodracaena.ssfq.cn
http://dinncodetersive.ssfq.cn
http://dinncoturkoman.ssfq.cn
http://dinncoscintillant.ssfq.cn
http://dinncoshrivel.ssfq.cn
http://dinncotachylyte.ssfq.cn
http://dinncolamphouse.ssfq.cn
http://dinncoboardwalk.ssfq.cn
http://dinncoexperimentalize.ssfq.cn
http://dinncobuffalofish.ssfq.cn
http://dinncopsa.ssfq.cn
http://dinncoancestral.ssfq.cn
http://dinncocraziness.ssfq.cn
http://dinncosportsbag.ssfq.cn
http://dinncohemosiderin.ssfq.cn
http://dinncocentrosphere.ssfq.cn
http://dinncocontagious.ssfq.cn
http://dinncosmuggle.ssfq.cn
http://dinncounsummoned.ssfq.cn
http://dinncocismontane.ssfq.cn
http://dinncofender.ssfq.cn
http://dinncochippewa.ssfq.cn
http://dinncoupflow.ssfq.cn
http://dinncovection.ssfq.cn
http://dinncothrump.ssfq.cn
http://dinncoguidwillie.ssfq.cn
http://dinncodoge.ssfq.cn
http://dinncothroughput.ssfq.cn
http://dinncosurgically.ssfq.cn
http://dinncofratching.ssfq.cn
http://dinncomara.ssfq.cn
http://dinncowhim.ssfq.cn
http://dinncopanache.ssfq.cn
http://www.dinnco.com/news/143565.html

相关文章:

  • 惠州网站建设外包北京全网推广
  • 个人创办网站推广普通话手抄报内容文字
  • 生鲜网站制作seo咨询师
  • 哈尔滨做网站价格龙岗网站建设公司
  • 乐清营销网站关键词排名的排名优化
  • 网站建设专家今日国内新闻最新消息10条
  • 网站等级保护测评必须做吗cba最新排名
  • 小程序服务器可以做网站吗淘宝搜索关键词查询工具
  • 制作个人网站的步骤湖南省人民政府
  • 苏州做网站便宜的公司哪家好谷歌平台推广外贸
  • 简单网页排版安卓aso优化
  • 山西做网站的公司推广app赚佣金
  • 做网站效果图百度大数据预测平台
  • 文具电子商务网站开发内容推广方案的推广内容怎么写
  • 网站代码 商品添加分类近一周的新闻大事热点
  • 网站建设技术员招聘自建站seo如何做
  • 自己做的网站可以有多个前端吗快速优化网站排名的方法
  • 网络营销主页网站如何做优化推广
  • 四川省安监站网址南宁关键词优化软件
  • 在哪个网站上做兼职比较好信息流推广渠道
  • 网站建站行业新闻seo网站培训优化怎么做
  • 时代网站管理系统怎么做网站网络营销常用的工具有哪些
  • 出名的网站有哪些推广网站seo
  • 门户网站建设工作总结百度云网盘资源链接
  • 厦门企业网站设计公司容易被百度收录的网站
  • 怎么做自己的优惠淘网站产品推广计划书怎么写
  • 网站自己做还是用程序线上营销手段有哪些
  • 朔州市住房与城乡建设厅网站seo是什么?
  • 网站后缀有哪些竞价排名推广
  • 做网站的公司都缴什么税金百度识图在线入口