asp.net与mysql数据库,ASP.NET,MySQL与SQL Server中的数据库连接

我正在使用MySQL在我正在进行的ASP.NET项目中,我做了一些测试来测试MySQL .NET提供程序的性能,但遗憾的是我对结果并不满意.

只打开连接的一个非常简单的循环在SQL Server中快了10倍:

// MySQL

const string CONNECTION_STRING =

"server=localhost;database=testdb;user id=root;password=mypassword;max pool size=250;";

for (int i = 0; i < 5000; i++)

{

using (MySqlConnection con = new MySqlConnection(CONNECTION_STRING))

{

con.Open();

}

}

// SQL Server

const string CONNECTION_STRING = "Data Source=localhost;Initial Catalog=testdb;Integrated Security=True;max pool size=250;";

for (int i = 0; i < 5000; i++)

{

using (SqlConnection con = new SqlConnection(CONNECTION_STRING))

{

con.Open();

}

}

SQL Server在其他任何方面都要快得多(选择,更新,插入……等).我做错了吗?我应该改变哪些服务器变量?

更多信息:

– 我在Windows上运行MySQL(5.0.51a-community-nt)

– 测试中使用了SQL Server 2005

– 规格:Windows XP SP2,CPU Intel 1.6GHz双核,1024 MB RAM

这是MySQL的配置:

[client]

port = 3306

socket = /tmp/mysql.sock

[mysqld]

port = 3306

socket = /tmp/mysql.sock

skip-locking

key_buffer = 384M

max_allowed_packet = 1M

table_cache = 512

sort_buffer_size = 2M

read_buffer_size = 2M

read_rnd_buffer_size = 8M

myisam_sort_buffer_size = 64M

thread_cache_size = 8

query_cache_size = 32M

thread_concurrency = 8

server-id = 1

[mysqldump]

quick

max_allowed_packet = 16M

[mysql]

no-auto-rehash

[isamchk]

key_buffer = 256M

sort_buffer_size = 256M

read_buffer = 2M

write_buffer = 2M

[myisamchk]

key_buffer = 256M

sort_buffer_size = 256M

read_buffer = 2M

write_buffer = 2M

[mysqlhotcopy]

interactive-timeout

谢谢你的任何建议……

解决方法:

默认情况下,SQL Server使用连接池:关闭时,使用完全相同的连接字符串打开的每个连接都将返回到池中.从池中返回连接比从头创建连接更有效.我假设默认情况下MySql不提供连接池

标签:mysql,net,sql-server,asp-net,connection-pooling

来源: https://codeday.me/bug/20190607/1193193.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值