从跨平台应用程序连接到MS SQL Server

时间:2021-08-29 04:34:12

I am working on a GUI application that will be used to perform "manual assessment" of large datasets produced by an AI algorithm. The nature of the assessment isn't important to this question; only the fact that the program will need to periodically check for new data from a server, download it, and then upload the results that the user produces. Each dataset is just a binary blob, as far as this question is concerned.

我正在开发一个GUI应用程序,该应用程序将用于对人工智能算法生成的大型数据集进行“手工评估”。评估的性质对这个问题并不重要;只是程序需要定期检查服务器上的新数据,下载它,然后上传用户生成的结果。就这个问题而言,每个数据集都只是一个二进制blob。

The machine that will host the data is currently set up with Microsoft SQL Server. For administrative reasons, I'll probably have to use SQL Server (rather than the web server that's running on the same machine) to store the data. I know SQL, and I doubt I'll have trouble learning Microsoft's version of it.

将托管数据的机器目前由Microsoft SQL Server设置。出于管理原因,我可能必须使用SQL Server(而不是运行在同一台机器上的web服务器)来存储数据。我知道SQL,我怀疑学习微软版本的SQL会有困难。


Here's the hard part: The program needs to run on Mac OS X and Windows. I don't have much experience with Windows development, and do most of my coding on a Mac using XCode — with a cross-compiler and a Windows VM to compile/test the Windows version. (However, I've already got the GUI working on Windows so that isn't the issue here. The code is in Objective-C but I'm happy to use pure C, or even C++, to access the database.)

难点在于:这个程序需要在Mac OS X和Windows上运行。我在Windows开发方面没有太多经验,我的大部分代码都是在Mac上使用XCode——使用交叉编译器和Windows VM编译/测试Windows版本。(但是,我已经让GUI在Windows上工作,所以这不是这里的问题。代码在Objective-C中,但是我很乐意使用纯C,甚至c++来访问数据库)。

The program just needs to connect to the SQL Server and perform simple queries. I'd really like a library that I can just link into my application so that it can do its thing — sort of I can with SQLite, but I'd obviously be passing a connection string rather than a database filename. I'd prefer for the end-user not to have to install anything extra on their machine. Here's what I've found so far:

这个程序只需要连接到SQL服务器并执行简单的查询。我非常想要一个可以链接到我的应用程序的库,这样它就可以做它的事情——我可以用SQLite来做,但是我显然是在传递一个连接字符串,而不是一个数据库文件名。我希望最终用户不要在他们的机器上安装任何额外的东西。以下是我迄今为止的发现:

  • Microsoft Data Access Components' ODBC interface — Windows only, and the latest version was released in 2005 which makes me wonder whether or not it supports to latest version of SQL Server.
  • 微软数据访问组件的ODBC接口——Windows only,最新版本发布于2005年,这让我怀疑它是否支持最新版本的SQL Server。
  • iODBC — runs on practically everything except Windows.
  • 碘缺乏病——除了窗户,几乎什么都可以。
  • FreeTDS — accesses SQL Server through the native protocol rather than through ODBC. Claims to run on "Linux/UNIX", but I was able to compile it on OSX without any problems.
  • FreeTDS——通过本机协议而不是通过ODBC访问SQL Server。声称在“Linux/UNIX”上运行,但是我能够在OSX上编译它,没有任何问题。

The last two are open-source. A quick look at the code shows that FreeTDS uses BSD sockets for connecting to the server (I haven't figured out yet what IODBC uses, but probably the same), and I can't see why any other part of the code would be non-portable. If necessary, I would be prepared to try porting the FreeTDS socket code to Winsock, if I could be fairly sure that I wouldn't run into any further obstacles.

最后两个是开源的。快速浏览一下代码就会发现FreeTDS使用BSD套接字来连接服务器(我还没弄清楚碘bc使用什么,但可能是一样的),我也不明白为什么代码的其他部分都是不可移植的。如果需要的话,我将准备尝试将FreeTDS套接字代码移植到Winsock中,如果我能相当确定我不会遇到任何进一步的障碍。


My question is:

Can I get one of these libraries (or anything else, for that matter) to link against both the Mac and Windows versions of my application?

我能让这些库(或者其他的什么)链接到我的应用程序的Mac和Windows版本吗?

If not, what's the best combination of libraries to use to ensure minimum hassle? In either case, are there any gotchas I need to know about when distributing the Windows version, such as DLLs that will need to be installed on users' machines?

如果不是,那么要使用哪些库来确保减少麻烦?无论哪种情况,在发布Windows版本(比如需要安装在用户机器上的dll)时,我是否需要了解这些问题?


Update:

On @TomTom's recommendation, I'm going to try FreeTDS. Despite what I initially thought, it does compile on Windows, and it seems that using a native implementation of TDS is considered better than ODBC, which is apparently 10 years out of date.

在@TomTom的推荐下,我将尝试FreeTDS。不管我最初的想法是什么,它确实可以在Windows上编译,而且似乎使用TDS的本地实现比ODBC更好,后者显然已经过时了10年。

2 个解决方案

#1


1  

Well, ODBC in general is outdated / semi-retired (for about 10 years, in case you wonder) and replaced b a faster / more easy to handle technology clled OleDb.

通常情况下,ODBC是过时的/半退役的(如果你想知道的话,可以使用大约10年),并且取代了b更快/更容易处理的技术clled OleDb。

That said, forget it - go for a TDS implementation and be happy with it.

也就是说,忘掉它吧——去实现TDS,并对它感到满意。

#2


3  

iOBDC is an ODBC Driver Manager and not an actual ODBC Driver, so if you were to use it an ODBC Driver would also be required for MS SQL Server. If you are developing on Mac OS X and have a cross compiler for Windows then you can make an ODBC application to perform these database operations you require on Mac OS X and then cross compile for Windows. The beauty of building an ODBC application is that all you then need to is source and ODBC driver for your target database and operating system, such that you are not looked into either. OpenLink Software for example have a suite of ODBC drivers for most popular relational databases including SQL Server, as detailed at http://uda.openlinksw.com/sqlserver-odbc/

iOBDC是一个ODBC驱动程序管理器,而不是实际的ODBC驱动程序,所以如果您要使用它,那么SQL Server也需要一个ODBC驱动程序。如果您正在Mac OS X上开发,并且有一个用于Windows的交叉编译器,那么您可以创建一个ODBC应用程序来执行在Mac OS X上需要的这些数据库操作,然后在Windows上交叉编译。构建ODBC应用程序的美妙之处在于,您接下来需要的是目标数据库和操作系统的源和ODBC驱动程序,这样就不会对您进行任何研究。例如,OpenLink软件为大多数流行的关系数据库(包括SQL Server)提供了一套ODBC驱动程序,详情请参见http://uda.openlinksw.com/sqlserver-odbc/

With regards to OLEDB, it might be a newer technology that ODBC, but has failed the test of time as it is Windows specific and has since been superseded by ADO.Net another Windows specific technology (unless you have Mono). Whereas ODBC is a major generic data access API available across most commercial OS'es Windows, Linux/Unix, Mac OS X etc. and continues to be supported and maintained by other third party vendors like OpenLink Software who will ensure it remains a robust and viable cross platform and database independent API.

对于OLEDB来说,ODBC可能是一种更新的技术,但是由于它是Windows专用的,因此没有通过时间测试,因此被ADO所取代。Net另一个Windows特定技术(除非你有Mono)。然而,ODBC是一种主要的通用数据访问API,可用于大多数商业操作系统的Windows、Linux/Unix、Mac OS X等,并继续得到其他第三方供应商(如OpenLink Software)的支持和维护,这些第三方供应商将确保ODBC仍然是一个健壮的、可行的跨平台和独立于数据库的API。

#1


1  

Well, ODBC in general is outdated / semi-retired (for about 10 years, in case you wonder) and replaced b a faster / more easy to handle technology clled OleDb.

通常情况下,ODBC是过时的/半退役的(如果你想知道的话,可以使用大约10年),并且取代了b更快/更容易处理的技术clled OleDb。

That said, forget it - go for a TDS implementation and be happy with it.

也就是说,忘掉它吧——去实现TDS,并对它感到满意。

#2


3  

iOBDC is an ODBC Driver Manager and not an actual ODBC Driver, so if you were to use it an ODBC Driver would also be required for MS SQL Server. If you are developing on Mac OS X and have a cross compiler for Windows then you can make an ODBC application to perform these database operations you require on Mac OS X and then cross compile for Windows. The beauty of building an ODBC application is that all you then need to is source and ODBC driver for your target database and operating system, such that you are not looked into either. OpenLink Software for example have a suite of ODBC drivers for most popular relational databases including SQL Server, as detailed at http://uda.openlinksw.com/sqlserver-odbc/

iOBDC是一个ODBC驱动程序管理器,而不是实际的ODBC驱动程序,所以如果您要使用它,那么SQL Server也需要一个ODBC驱动程序。如果您正在Mac OS X上开发,并且有一个用于Windows的交叉编译器,那么您可以创建一个ODBC应用程序来执行在Mac OS X上需要的这些数据库操作,然后在Windows上交叉编译。构建ODBC应用程序的美妙之处在于,您接下来需要的是目标数据库和操作系统的源和ODBC驱动程序,这样就不会对您进行任何研究。例如,OpenLink软件为大多数流行的关系数据库(包括SQL Server)提供了一套ODBC驱动程序,详情请参见http://uda.openlinksw.com/sqlserver-odbc/

With regards to OLEDB, it might be a newer technology that ODBC, but has failed the test of time as it is Windows specific and has since been superseded by ADO.Net another Windows specific technology (unless you have Mono). Whereas ODBC is a major generic data access API available across most commercial OS'es Windows, Linux/Unix, Mac OS X etc. and continues to be supported and maintained by other third party vendors like OpenLink Software who will ensure it remains a robust and viable cross platform and database independent API.

对于OLEDB来说,ODBC可能是一种更新的技术,但是由于它是Windows专用的,因此没有通过时间测试,因此被ADO所取代。Net另一个Windows特定技术(除非你有Mono)。然而,ODBC是一种主要的通用数据访问API,可用于大多数商业操作系统的Windows、Linux/Unix、Mac OS X等,并继续得到其他第三方供应商(如OpenLink Software)的支持和维护,这些第三方供应商将确保ODBC仍然是一个健壮的、可行的跨平台和独立于数据库的API。