c# - What will happen to some connection with same connect string? -
this question has answer here:
let have 4 mysql connection , connectstring (i leave connection pooling enabled, i'm using mysql .net connector mysql itself)
protected internal mysqlconnection connection; protected internal mysqlconnection cnnct1,cnnct2,cnnct3; protected internal string connectstring = "server=" + addressbox.text + ";database=" + dbnamebox.text + ";uid=" + userbox.text + ";password=" + passbox.text + ";";
then assign connections
protected internal void connectionmaker() { connection = new mysqlconnection(connectstring); cnnct1 = new mysqlconnection(connectstring); cnnct2 = new mysqlconnection(connectstring); cnnct3 = new mysqlconnection(connectstring); }
what connections is, since app multi-threaded , thread require access single database concurrently @ same time think give each thread different connection, since they're accessing same db, same table think give each connection same connect string.
for addition each thread executing mysqlreader
select
command on same columns on single table @ same time (through task parallel libary), each of them read different rows
my questions are, i'm trying make code simple , easy possible, yet safe, good, , correct practice ? if not, there simple yet safe approach i'm going ?
if connection string same connections use same connection pool.
the best practice every thread creates, opens , closes own connection, framework take care of sharing resources when it's possible.
i suggest give here: https://msdn.microsoft.com/en-us/library/vstudio/8xx3tyca%28v=vs.100%29.aspx
whenever user calls open on connection, pooler looks available connection in pool. if pooled connection available, returns caller instead of opening new connection. when application calls close on connection, pooler returns pooled set of active connections instead of closing it. once connection returned pool, ready reused on next open call.
Comments
Post a Comment