|
With ADO (both System.Data.Oledb and System.Data.Sql namespaces) connection pooling is active by default, and your connection string does nothing to turn it off.
If you are using SQL server (which your connection string says you are) you should use the SQLClient class rather than the OledbClient. The SQL client is much more performant. See the framework documentation on connection string settings to control the pooling.
I'm not sure why you would want to disable the pooling, since this significantly improves performance on reopening connections with the same connection string...
Absolute faith corrupts as absolutely as absolute power
Eric Hoffer
The opposite of the religious fanatic is not the fanatical atheist but the gentle cynic who cares not whether there is a god or not.
Eric Hoffer
|
|
|
|
|
hi Rob,
Thanks for the reply.
Its not that I want to disable connection pooling, its just that I've taken it out of the equation. If fact I definitely want pooling.
VB and c++ are using ADO though, so while i understand and agree with you that I should be using the sqlclient class for c#, this doesnt have an effect on the VB and c++ as im using ADO and not ADO.net.
Any other ideas?
Q
Quintes
|
|
|
|
|
I'm confused. Are there 3 different apps, 1 VB (6?), one C++ (VC6?) and one C#?
If not, and all are VS2003 based, then all of them could use SqlClient namespace - VB.Net, C# both have access to this namespace, and C++ does as well through the managed classes (which can be mixed with unmanaged code like MFC if need be).
If they are a mix of legacy and new apps, then the older ones could continue to use ado (your present install must be putting the right stuff in...) and the new C# could move on to the SqlClient namespce stuff which is a different Oledb Provider. All have independant connection pools now anyway (even if the connection strings are the same, they are different processes, so each gets a new pool)...
Absolute faith corrupts as absolutely as absolute power
Eric Hoffer
All that is necessary for the triumph of evil is that good men do nothing.
Edmund Burke
|
|
|
|
|
guys, not sure why this one isn't working right, but i need to check the db for that info and if it is null push exception 1 if its not then verify the string saved on the table, if that doesn't pass then push exception 2
enclosed is the C# code....
dataConnection.ConnectionString = "user ID=sa; Pwd=password;Initial Catalog=mydb;Data Source=mycomputer";
dataConnection.Open();
dataCommand.Connection = dataConnection;
dataCommand.CommandText = "SELECT password FROM users WHERE username = 'dash' ";
dataReader = dataCommand.ExecuteReader(CommandBehavior.CloseConnection);
while (dataReader.Read())
{
if (dataReader["password"].ToString()!=null)
{
if (dataReader["password"].ToString().Equals("board"))
{
dataReader.Close();
}
else MessageBox.Show("Sorry, unable to verify license at this time \n\r Please try again later, or contact the system administrator.", "Incorrect License");
}
else MessageBox.Show("Sorry, We are unable to verify your license at this time. \n\r Please try again later, or contact the system admin.");
}
PS... I put a space between the user id and password becaues the browser was inputting a smiley!
Dim Beautiful As String
Beautiful = "ignorant"
Label1.Text = "The world is full of " & Beautiful & " people."
Why is common sense such an un-common comodity?
|
|
|
|
|
First, since you are only expecting a single value, I would use ExecuteScalar instead of a DataReader:
dataCommand.Connection = dataConnection;
dataCommand.CommandText = "SELECT password FROM users WHERE username = 'dash' ";
try
{
object o = dataCommand.ExecuteScalar();
if(o == null)
{
...
}
else
{
string thePwd =(string)o ;
if(thePwd.Equals("myPwd"))
{
...
}
}
}
finally
{
dataConnection.Close();
dataConnection.Dispose();
}
....
Note that I did not use ToString() to convert the return value, but instead cast the object to a string. ToString is not strictly a conversion function, but instead returns the 'string representation' of an object. what ToString returns could be different from the 'value' of the object as a string. Also note that your comparison is case sensitive...
Absolute faith corrupts as absolutely as absolute power
Eric Hoffer
The opposite of the religious fanatic is not the fanatical atheist but the gentle cynic who cares not whether there is a god or not.
Eric Hoffer
|
|
|
|
|
Rob,
finally got a chance to plug this in and i'm having some problems....
i get a specified cast is not valid on the string thePwd = (string)o ; it looks like it is creating the thePwd as null rather than failing at the first if.
I've enclosed the whole try/catch block. also want to note that i WAS able to run the if statements properly if the data field was NOT null, but when i set it to null i get the cast not valid error. code is shown as tested, have not begun to add the commented areas yet.
thanks
try
{
object o = dataCommand.ExecuteScalar();
if(o == null)
{
InitializeComponent2();
dataConnection.Close();
dataConnection.Dispose();
}
else
{
string thePwd =(string)o ;
if(thePwd.Equals("board"))
{
dataConnection.Close();
dataConnection.Dispose();
InitializeComponent();
InitialTransAxs();
Connection();
}
}
}
catch (Exception e)
{
MessageBox.Show("(003) Sorry you are not authorized to view this material." +e.Message +e.StackTrace);
}
finally
{
dataConnection.Close();
dataConnection.Dispose();
}
Dim Beautiful As String
Beautiful = "ignorant"
Label1.Text = "The world is full of " & Beautiful & " people."
Why is common sense such an un-common comodity?
|
|
|
|
|
Hmm, guess it returns a null for the object only if the record is not found, and an object wiith ans sqlNull value if the record is found but the field is null.
a simple solution woud be to change the cast to a 'silent fail' cast:
string thePwd = o as string;
if(thePwd != null)
{
if(thPwd.Equals("board")
{
dataconnection.Close(0);
....
}
}
else
Absolute faith corrupts as absolutely as absolute power
Eric Hoffer
All that is necessary for the triumph of evil is that good men do nothing.
Edmund Burke
|
|
|
|
|
k, i noticed you put the second if inside the first, was that intentional?
if so that will make my process a bit more difficult....
Dim Beautiful As String
Beautiful = "ignorant"
Label1.Text = "The world is full of " & Beautiful & " people."
Why is common sense such an un-common comodity?
|
|
|
|
|
if the 'as' cast fails, thePwd will be a null (uninitialized object) so the Equals() call would throw an exception, so I tested for this first.
A suggestion:
<pre>
bool loginOk = false;
string thePwd = o as string;
if( thePwd != null)
{
if( thePwd.Equals("board"))
{
loginOk = true;
}
}
if(loginOk == true)
{
// initialise your stuff
}
else
msgbox("can't Log in...");
</pre>
<small><b>Absolute faith corrupts as absolutely as absolute power<i>
Eric Hoffer</i></b></small>
<small><b>All that is necessary for the triumph of evil is that good men do nothing.
<i>Edmund Burke</i></b></small>
|
|
|
|
|
First of all i´d like to say Hi to all the members of this forum, and say thanks to the webmasters of this page; it´s a great one
My problem is the following:
I started developing VB.NET App about 5 months ago, and i am very concerned about database performance, because the software I develope at my job mainly involves using them.
I´ve been working on a project for about 2 months that uses an access database shared on a network folder (yep, that sucks i know) and i´d really like that someone tell me about a webpage or a book from where i can gain some expertise about that.
Currently, my app does one operation where it has to make several select and update commands, making the process very slow... While making that, the form of the app stutters, tried to use application.doevents, but was not very effective... should it be wise to create a thread and complete the operation in that thread?
As you see, i´m very newbie to this, and i feel a little lost... Hope that someone can lead me hand. Thanks a lot for reading, and sorry about my english
|
|
|
|
|
i need to clear all connection to the mssql server database via t-sql(the action that we can do by enterprise manager). because i want to restore database, but when it has some connection , i cant do that in my application. my application works in network and in the restore time, other clients may have transaction(s) on database. sql server doesnt allow to a client to restore but the restoring client is admin AND he realize to restore in this time, however other clients are working with database at the same time.
Thanks
Rastegar
|
|
|
|
|
Try this
ALTER DATABASE DatabaseName WITH ROLLBACK IMMEDIATE RESTORE DATABASE
DatabaseName FROM DISK = 'C:\DatabaseBackup.bak'
The ALTER DATABASE command will automatically kill all connections to the database being restored. This command prevents the need to query master.dbo.sysprocesses to kill existing connections in order to complete the restore.
Alomgir Miah
Live Life King Size
|
|
|
|
|
im so sorry but your code in query analyzer make these errors:
Server: Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'WITH'.
Server: Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'IMMEDIATE'.
could you please correct it and send me.
Thanks
Rastegar
|
|
|
|
|
Which version of SQL server you are using
Alomgir Miah
Live Life King Size
|
|
|
|
|
Restore an entire database:
RESTORE DATABASE { database_name | @database_name_var }
[ FROM < backup_device > [ ,...n ] ]
[ WITH
[ RESTRICTED_USER ]
[ [ , ] FILE = { file_number | @file_number } ]
[ [ , ] PASSWORD = { password | @password_variable } ]
[ [ , ] MEDIANAME = { media_name | @media_name_variable } ]
[ [ , ] MEDIAPASSWORD = { mediapassword | @mediapassword_variable } ]
[ [ , ] MOVE 'logical_file_name' TO 'operating_system_file_name' ]
[ ,...n ]
[ [ , ] KEEP_REPLICATION ]
[ [ , ] { NORECOVERY | RECOVERY | STANDBY = undo_file_name } ]
[ [ , ] { NOREWIND | REWIND } ]
[ [ , ] { NOUNLOAD | UNLOAD } ]
[ [ , ] REPLACE ]
[ [ , ] RESTART ]
[ [ , ] STATS [ = percentage ] ]
]
Live Life King Size
Alomgir Miah
|
|
|
|
|
mssql2000
Thanks
Rastegar
|
|
|
|
|
hey!nice to meet you,everyone.you can call me bill.can we make friends?
recently i posted a problem on the forum,but hasnot had an answer.could
you please help me?i'm worring about it.my question is:how to serialize
(save) object into SQL Server?for a instance:
<serializable()>_
public class employee
private _name as string
private _age as string
public property name() as string
get
return me._name
end get
set(byval value as string)
me._name=value
end set
end property
.........
maybe use DataSet as interface,but i failed.i think you are a
warmhearted man.please help me.thank you very very much.
good luck and make more money! bill(in Code Project's name is:maaaxwell)
|
|
|
|
|
maaaxwell wrote:
i think you are a warmhearted man
Some of us are warm hearted, and some of us are men. Not all are both, or even either
To serialise an object, you need to store it as a stream of bytes, so the first step is being able to convert an object to a byte stream. I'm pretty sure that's what serialising a class does anyhow. Basically the steps are:
1. convert object to bytes
2. store bytes in DB
3. get bytes back
4. convert bytes back into object.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
hey!thanks for your reply!yeah,you are a warm hearted man
i know the four steps you wrote,but i havenot had any idea about how to serialize them into database(SQL Server),could you please write in detail?
thanks!
maaaxwell
|
|
|
|
|
I can't provide more detail because I have no idea what your objects are. What are you trying to store ?
Here[^] is an article on serializing classes. Once you have the ability to serialise to a stream, you can build a string to pass to the SQL, and use that string to deserialise.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
How can I create a DTS package dynamically? I want to transfer data from tables in sql server to an access database.
The access database already exists but not the tables. The tables in the access database need to be created on the fly because I don’t know what tables will be transferred.
Thanks,
Martin
|
|
|
|
|
Check here
"People who never make mistakes, never do anything."
My blog
http://toddsnotsoamazinglife.blogspot.com/
|
|
|
|
|
Hi,
I'm trying to get/set datetime field of exchange item (in resolution of Milliseconds) - using ADO.RecordClass.
However it seemed that after I call Record.Update (in set case) the datetime value is rounded in seconds resolution.
(i.e. trying to set 19:00:00.111 --> result with 19:00:01.000)
Please note - I'm using C# language to do so.
Can anyone help me to overcome this problem?
10x,
Zachi
|
|
|
|
|
I always use TimeSpan or DateTime as they have access to millisecond, please explain a little bit more why you are using ADO.RecordClass
Thanks
Al
|
|
|
|
|
Hi,
First, Thanks for your reply.
Here is the thing - I'm using ADO (as interop in c# project) to access exchange storage items.
When I tried to access record field of type 'datetime.tz' (using Record.Fields[<fieldname>].Value) either for reading or for writing - it seemed that ADO round DateTime fields with resolution of seconds (i.e. instead of getting '12:00:00.123' --> I'm getting '12:00:01').
Also, I'm using Exchange-Explorer tool to read/modify 'datetime.tz' field it succeed to do so (with resolution of milliseconds).
It is strange - but I checked retrieval using OLE-DB (not ADO) and it succeed to bring resolution of milliseconds (as should).
I will be more than grateful if you can help me with this one.
10x,
Zachi
|
|
|
|