|
I run an application in my computer with the sqlserve installed in my computer too.
But when my code goes to :
SqlConnection conn = new SqlConnection("...");
conn.Open();
It's very strange that sometime it took so long to open the connection, about 4 seconds. But sometime it's fast, it took no more than 1s to finish.
I tried it many times. All the tests are done after restarting the computer, so the environment should be very clean.
Any one know why? Please kindly tell me.
Thanks in advance!
|
|
|
|
|
Post your connection string (hash the server ip, password and username first) so we can see if there is a problem in there.
Otherwise where is this SQL server you are connecting to in relation to the box running the code?
regards,
Paul Watson
Bluegrass
South Africa
Miszou wrote:
I have read the entire internet. on how boring his day was.
Crikey! ain't life grand?
|
|
|
|
|
How is your computer resolving the location of the server? If your connection string uses the server name, it must be resolved to an IP address, which might take a bit of time if you are depending on netbios (windows workgroup) to get the job done. Will be worse if you have multiple newtork adapters...
Iry putting the servers IP info in LMHOSTS.
Genius may have its limitations, but stupidity is not thus handicapped. - Elbert Hubbard
|
|
|
|
|
The first time a connection is made to the server, it has to perform authentication, set up various parameters, and perform other initialisation.
When using connection pooling, a 'closed' connection (from the application's perspective) is not in fact closed. It's kept in the pool waiting to be reused. When you 'open' a connection and there's at least one spare connection in the pool, the provider simply resets the connection ("EXEC sp_reset_connection" in SQL Profiler trace output) and hands it out. This explains the sub-second connection time.
When there aren't any connections, but the pool can hold more (maximum not yet reached), it will have to do a proper connection in the same way as the first one. This will take about the same amount of time as the first did.
|
|
|
|
|
How do I do this?
I need to receive the data this way:
12 10
I fI have the following structure.
select sum(total)as total1
from table1
12
select sum(total)as total2
from table1....
10
|
|
|
|
|
Anonymous wrote:
I need to receive the data this way:
12 10
If you are referring to having the items both returned by the query in one record instead of two sets, you use a union.
select sum(total) as total1, null as total2
from table1
union
select null, sum(total)
from table2
Rocky <><
www.GotTheAnswerToSpam.com
|
|
|
|
|
How can I check when the last time db was restore?
|
|
|
|
|
Do you have access to the server utilities? or are you asking about how to do it programatically?
|
|
|
|
|
Hi !
In my application, I use a SQL command to create a table in an Access database (with ODBC).
I want ot have a text field, and I create it like this :
Name VARCHAR(128)
My problem is that in Access, this text field is set to : Empty String Not Allowed, but I want to allow empty string. How can I specify that in my SQL command ?
Thanks !
Jerome
|
|
|
|
|
Hello!
You should be able to simply modify your CREATE statement to something that looks like this:
Name VARCHAR(128) NULL
to explicitly allow null strings. Then again, writing
Name VARCHAR(128) NOT NULL
will explicitly require NON-NULL strings.
I hope this helps.
Cypher.
|
|
|
|
|
Thanks for answering, but the problem remains. Your solution does allow to have a NULL string, but doesn't allow to have an empty string (which is not a null string !).
Any ideas ?
Jerome
|
|
|
|
|
Jerome Conus wrote:
but doesn't allow to have an empty string
And you get some error message telling you this?
Someone correct me if I'm wrong, but I think that any attempt to store an empty string in a varchar type column will result in that column being set to NULL.
Chris Meech
It's much easier to get rich telling people what they want to hear. Chistopher Duncan
But for a man, barbecuing eggplant and portobello mushrooms is a sure way to have people question your sexual orientation. Kuro5hin
|
|
|
|
|
The thing is that in Access, there are two properties on a text field :
'NULL allowed'
and
'Empty string allowed'
But, with the SQL language, I don't know how to set these two properties.
This command :
CREATE T_Dummy (Label VARCHAR(30) NOT NULL);
Will change the first property (NULL allowed) but not the second one, which by default says 'no empty string allowed' and which is the one I'd like to change.
I couldn't find in the SQL language reference a way to change the second property and I wonder if it is something only Access understands.
Jerome
|
|
|
|
|
Jerome Conus wrote:
I wonder if it is something only Access understands
You are probably hitting the nail on the head. You'll have to dig through some Access specific programming reference books to likely find any mention of it. Good Luck
Chris Meech
It's much easier to get rich telling people what they want to hear. Chistopher Duncan
But for a man, barbecuing eggplant and portobello mushrooms is a sure way to have people question your sexual orientation. Kuro5hin
|
|
|
|
|
Allow zero length is an Access specific property and cannot be set with SQL.
Just one more reason not to use Access.
Genius may have its limitations, but stupidity is not thus handicapped. - Elbert Hubbard
|
|
|
|
|
DECLARE @variableProc1 varchar(100)<br />
SET @variableProc1 = 'Val 1';<br />
EXECUTE('DECLARE @variableExec1 varchar(100); SET @variableExec1 = ''In variableExec1''; Print @variableExec1; ')<br />
--EXECUTE('DECLARE @variableExec2 varchar(100); SET @variableExec2 = ''In variableExec2'';')<br />
--SET @variableProc1 = variableExec2;<br />
PRINT @variableProc1;
Hi
In this example, I am able to print the value of @variableExec1, as long as I print it with EXECUTE context.
If I try assign the value of @variableExec2 to @variableProc1, it throws an error. Which I think because they are in different context.
My question is, how can I assign the value of @variableExec2 to @variableProc1 ?
Please advice. Thanks
Pankaj
Follow your goals, Means will follow you ---Gandhi---
|
|
|
|
|
You can't. The variable is declared only in the scope of the execute statement.
Genius may have its limitations, but stupidity is not thus handicapped. - Elbert Hubbard
|
|
|
|
|
Hi, in my server explorer produces this error msg :
"server explorer is unable to perform this operation"
"the requested name is valid, but no data of the requested type was found"
but i was able to connect the database to my program!
can someone tell me whats wrong....thanks
I really need an e-book about SQL server 2000, can anyone tell me where can I get one!?
nevhile.net
|
|
|
|
|
|
I have 4 databases named: db1, db2, db3, db4 on the same SQL Server. All 4 databases have the same table Department(ID, Name) but the data is different. For example:
Table ID Name
db1.Department 1 Dept1
db2.Department 1 Dept2
db3.Department 1 Dept3
db4.Department 1 Dept4
I use SQL Query analyzer to execute the code fragment below:
declare @n int
declare @Name nvarchar(256)
set @n = 1
while (@n < 5)
begin
if (@n = 1) use db1
else if (@n = 2) use db2
else if (@n = 3) use db3
else if (@n = 4) use db4
select [Name] from Department where [ID] = 1
set @Name = [Name] from dbo.Department where [ID] = 1
print @Name
set @n = @n + 1
end
The results:
---------------------------------
Dept1
Dept4
---------------------------------
Dept2
Dept4
---------------------------------
Dept3
Dept4
---------------------------------
Dept4
Dept4
But I think the correct result should be
---------------------------------
Dept1
Dept1
---------------------------------
Dept2
Dept2
---------------------------------
Dept3
Dept3
---------------------------------
Dept4
Dept4
The question is: Is there anything wrong from me or from SQL???
|
|
|
|
|
It sounds like your first conditional is falling through to the last case.
Have you tried running it with conditions you know will always be false?
It looks like it should work....
|
|
|
|
|
Below is my query. When I do a count it is counted all location,I want to be have a count after group by executes. How do I do this?
SELECT a.Number, a.Location,count(a.Location)'Number'
FROM Reports_Location
GROUP BY a.Number, a.Location
|
|
|
|
|
Not sure of the meaning. But if you are looking for a count of locations you could try this
select count(*) from (
select unique location from reports_location
)
;
Chris Meech
It's much easier to get rich telling people what they want to hear. Chistopher Duncan
But for a man, barbecuing eggplant and portobello mushrooms is a sure way to have people question your sexual orientation. Kuro5hin
|
|
|
|
|
Hi all,
I'm a .NET newbie, and just kind of a programming/developing wannabe. I'm moving into C# from a (tiny) background in JavaScript only. I administer a club website in ASP and want to switch to ASP.NET. Here's my conundrum:
I have a membership database (Access) that includes a field for when a record was last updated (UpdDt), and who updated it (UpdLogin). The value in UpdLogin is a member's ID number, correlating to the MbrId field.
I want to show administrators a list of all members that were updated recently, and who updated them. I need to not just show the UpdLogin value, but the actual name of the person who did the update. So I need to (for each record) find the name, within the table I'm already using as the DataSource, and show that as "Updated By".
In ASP, I created 2 recordsets and looped through the first. For every record, I used:
rs2.MoveFirst<br />
rs2.Find("MbrId = "+updLogin)
then (making sure the record existed) grabbed the name.
I think it was inelegant, and probably inefficient, but it worked.
SO! How the heck do I do this in .NET? I'm still working on wrapping my head around DataGrids and DataSets and DataAdapters and DataViews and OhMyGoodnessDoesItEverEnd...
Have I missed some simple SQL solution to this? Do I require a couple of tables in a DataSet, and use some method similar to what I did in ASP?
Please, help a poor newbie in need!
Best Regards,
Kevin Swanson
http://bcmc.ca[^]
|
|
|
|
|
Why don´t you get all the data in a snigle query ?
Free your mind...
|
|
|
|