这几天研究Linux平台下,如果通过桌面程序和ASP.net访问SqlServer数据库和Oracle数据库,发现网上写的好多文章都不完善,很多是无用的多余的设置,而又不讲原理,本人研究了几日,经证实如下设置完全能满足要求。 前提:OS:CentOS5.5 A.安装mono2.6 增加一个
这几天研究Linux平台下,如果通过桌面程序和ASP.net访问SqlServer数据库和Oracle数据库,发现网上写的好多文章都不完善,很多是无用的多余的设置,而又不讲原理,本人研究了几日,经证实如下设置完全能满足要求。
前提:OS:CentOS5.5
A.安装mono2.6
增加一个新的代理文件,写入http://ftp.novell.com/pub/mono/download-stable/RHEL_5/。这是mono官方提供的针对CentOS的最新的mono平台。
yum --disablerepo=extras *mono* (注意:/etc/yum.repos.d/CentOS-Base.repo中的[extras]节也有一个版本的mono,不过很老了应该是1.1版本的,这里屏蔽掉了这个源,从而只安装最新版本的mono)
安装完后,会自动修改httpd相应的设置,无需手工再修改之。
B.安装freetds
yum install freetds
C.安装OracelInstantClient
去官方下载.zip压缩文件即可,就几十MB大小,解压到/opt/oracle/。
0. Linux下访问Oracle和SqlServer的小工具
0.1命令行访问SqlServer
安装完freetds后,会安装一个名为tsql的小工具,基本使用方法:
#tsql -S SqlServer服务器IP地址 -p 端口号 -U 用户名 -P 密码
正确登陆后,出现如下提示符:
>
输入
>select * from 表名;回车
>go;回车
然后会显示查询的内容。
0.2命令行访问Oracle
安装好InstantClient后,再下载一个sqlplus(很小)解压都同一目录下即可。把这一目录加入PATH
然后执行如下命令连接远程Oracle数据库
#sqlplus 用户名/密码@服务器IP/实例名
成功登陆后显示
SQL >
输入
SQL> select * from 表名;回车
即可看到查询结果。
1. Linux下mono访问SqlServer数据库
调用方式:
mono在调用方式上与.net Framework完全相同,都是采用System.Data.SqlClient命名空间中的类来完成数据库操作。
实现原理:
System.Data.SqlClient中的类库的实现靠的是通过P/Invoke调用freetds共享库的函数完成。所以必须安装freetds,在CentOS5.5中通过yum install freetds完成。
示例代码:
sqlserver.cs
编译命令:gmcs -r:System.Data sqlserver.cs
运行命令:mono sqlserver.exe
2.Linux下mono访问Oracle数据库
调用方式:
mono在调用方式上与.net Framework完全相同,都是采用System.Data.OracleClient命名空间中的类来完成数据库操作。
需要注意的是,目前微软已经不建议在.net 平台上用System.Data.OracleClient了,因为Oracle自己提供了一个Oracle.Data.Access类库来提供.net对Oracle数据库的访问。然而在mono平台上,System.Data.OracleClient仍是最好的访问Oracle数据库的方式。
实现原理:
System.Data.OracleClient中的类库的实现靠的是通过P/Invoke调用libclntsh.so共享库的函数完成。需要安装Oracle提供的InstantClient,这个软件是典型的绿色软件,下载后解压即可。需要注意的是要让mono能找到这个共享库,因此需要把它所在的路径加入LD_LIBRARY_PATH环境变量。例如解压后目录是/opt/oracle/instantclient_11_2,那么需要在/etc/profile中,写入如下:
export LD_LIBRARY_PATH=/opt/oracle/intantclient_11_2:$LD_LIBRARY_PATH,另外还需要设置NLS_LANG如下:
export NLS_LANG=AMERICAN_AMERICA.UTF8
最后做个软连接
ln -s /opt/oracle/instantclient_11_2/libclntsh.so.0.0.0 /opt/oracle/intantclient_11_2/libclntsh.so
然后执行ldconfig刷新缓存。
此时mono已经能够访问oracle数据库了。
示例代码:
oracle.cs
编译指令:gmcs -r:System.Data.OracleClient oracle.cs
运行指令:mono oracle.exe
3.基于Apache的mono对SqlServer的访问
在CentOS下,如果通过yum安装的freetds和mono以及mod_mono,那么没有什么问题了,与1基本相同。不再累述。
4.基于Apache的mono对Oracle的访问
这里需要注意,在/etc/profile设定的LD_LIBRARY_PATH和NLS_LANG等环境变量,在httpd里并不知情,httpd是服务程序,不是从shell启动的。此时/opt/novell/mono/bin/mod-mono-server也是通过httpd启动的,所以也不知道这些环境变量,这样导致了mono无法确定需要通过p/Invoke调用的libclntsh.so,所以会导致无法访问Oracle.解决方式:
修改/opt/novell/mono/bin/mod-mono-server,修改后如下:
#!/bin/sh
export LD_LIBRARY_PATH=/opt/oracle/instantclient_11_2:$LD_LIBRARAY_PATH
export NLS_LANG=AMERICAN_AMERICA.UTF8
exec /opt/novell/mono/bin/mono $.................................
然后重新启动httpd服务即可。
如果需要在JDBC下访问Oracle和SqlServer,参见我的另一篇博客:http://blog.csdn.net/smstong/article/details/8129536

InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

MySQL is worth learning because it is a powerful open source database management system suitable for data storage, management and analysis. 1) MySQL is a relational database that uses SQL to operate data and is suitable for structured data management. 2) The SQL language is the key to interacting with MySQL and supports CRUD operations. 3) The working principle of MySQL includes client/server architecture, storage engine and query optimizer. 4) Basic usage includes creating databases and tables, and advanced usage involves joining tables using JOIN. 5) Common errors include syntax errors and permission issues, and debugging skills include checking syntax and using EXPLAIN commands. 6) Performance optimization involves the use of indexes, optimization of SQL statements and regular maintenance of databases.

MySQL is suitable for beginners to learn database skills. 1. Install MySQL server and client tools. 2. Understand basic SQL queries, such as SELECT. 3. Master data operations: create tables, insert, update, and delete data. 4. Learn advanced skills: subquery and window functions. 5. Debugging and optimization: Check syntax, use indexes, avoid SELECT*, and use LIMIT.

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

MySQL is an open source relational database management system that is widely used in Web development. Its key features include: 1. Supports multiple storage engines, such as InnoDB and MyISAM, suitable for different scenarios; 2. Provides master-slave replication functions to facilitate load balancing and data backup; 3. Improve query efficiency through query optimization and index use.

SQL is used to interact with MySQL database to realize data addition, deletion, modification, inspection and database design. 1) SQL performs data operations through SELECT, INSERT, UPDATE, DELETE statements; 2) Use CREATE, ALTER, DROP statements for database design and management; 3) Complex queries and data analysis are implemented through SQL to improve business decision-making efficiency.

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools