SqlConnection ..what Should I Expect ??

Aug 18, 2006

Hi all,

I'm trying to connect to my SQL SERVER 2000 database via Sqlconnection command with the code below,do I need to do something else to make sure the database is really opened ..I keep getting error at

conn.Open(); which I dont know what do about ..

any help will be really appreciated



using (SqlConnection conn = new SqlConnection("Server=" + dbServer+";Database="+dbDatabase+";"))

{

conn.Open();

SqlCommand cmd = conn.CreateCommand();

cmd.CommandText = "SELECT * FROM LOCATIONS";

cmd.ExecuteNonQuery();

conn.Close();

}





thanks

Alaa M

View 7 Replies


ADVERTISEMENT

How Would You Find Out Whether A SQL Query Is Using The Indices You Expect?

May 16, 2004

Hello, everyone:

This is testing question from a tesing seb site. Any reply will be appreciated.

ZYT

View 3 Replies View Related

Error Reportings -- To Except Or Not Expect Or Return?

May 11, 2007

You have seen a chair in a public room and go back after a while to acquire it. Is it unexpected that the object is not there anymore?

I implement the business logic in stored procedures. Once user orders some service, the actions carry out are: a)check they have sufficient funds on their balance; and, b) a price check is made selecting the latest from pricelist. The newly created job entry refers the price in the pricelist table according to service_id and the issued pricelist date.

These are data validity checks, which must be done in a multiuser database. In the session beginning, user gets prices and funds. These data are not locked throughout the session -- another process may change the records. Therefore, the extra "business" checks are needed to preserve data correctness at the start of every transaction. One way to report the errors would be to raise an error.

Consider the primary-foreign key violations. They are raised by system with severity level of 16. Uniqueness violation is raised with severity 14. The MSSQL reference http://msdn2.microsoft.com/en-us/library/ms164086.aspx tells us that this is a sort of error, which can be corrected by user. Indeed, (s)he can. But the exceptions are unexpected situations. Exception processing consumes huge CPU processing power if some occurs. Normally, programs allocate resources and use them. If resource cannot be allocated -- app exits with exception. It just has nothing to do. However, there is nothing exceptional in shared data access by multiple concurrent processes in a multithread/multiuser/distributed application. Since, we cannot lock the user resources during user session, we should be prepared to concurrent data changes. Therefore, I find the exception raising inappropriate tool.

Consider a situation, when one user is assigned to a group. Nothing prevents from another admin to remove the group at the same time. Therefore, our user management application should be ready to expected "group does not exist" "error" result. I even disagree that this is an error, since it is perfectly valid to have such a situation. It is like you have seen a chair in a room and later return to take it. But the chair is not there anymore. Is it unexpected? The case should not be exceptional, IMO.


So we have:
1. Severity 1-10 "informational messages";
2. Severity 11-16 errors; and
3. RETURN error_code.

Which should be used? Anything else? Do my considerations make sense?

View 8 Replies View Related

Query Optimizer Does Not Use The Index I Expect

Jun 27, 2007

I am trying to resolve performance issues in a third party application. I have run the profiler and found a transaction that performs a table scan against a 6 million row table. This transaction occurs repeatedly, so I thought, just add an index on the columns in the where clause used here. After adding the index, I looked at the estimated execution plan in Query analyzer, and I find that it is still performing the table scan. If I run the query it takes over 60 seconds to run, if i add an index hint, it runs in under a second. I ran DBCC SHOW_STATISTICS to see if the statistics were up to date:

Statistics for INDEX 'IX_Finish_dept'.
Updated Rows Rows Sampled Steps Density Average key length
-------------------- -------------------- -------------------- ------ ------------------------ ------------------------
Jun 26 2007 5:18PM 6832336 6832336 150 2.1415579E-7 18.0

(1 row(s) affected)

All density Average Length Columns
------------------------ ------------------------ ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2.1875491E-7 8.0 finish
1.9796084E-7 18.0 finish, dept

(2 row(s) affected)

RANGE_HI_KEY RANGE_ROWS EQ_ROWS DISTINCT_RANGE_ROWS AVG_RANGE_ROWS
------------------------------------------------------ ------------------------ ------------------------ -------------------- ------------------------
1900-01-01 00:00:00.000 0.0 106110.0 0 0.0
2001-02-01 17:00:00.000 54121.0 47.0 22951 2.3581107
2001-02-28 17:00:00.000 44436.0 22.0 18121 2.4520473
2001-04-06 00:00:00.000 56830.0 76.0 24902 2.2820544
2001-08-10 17:00:00.000 196491.0 19.0 88800 2.2127116
2001-09-02 17:00:00.000 33070.0 50.0 15289 2.162993
2001-10-05 17:04:59.997 57975.0 30.0 22882 2.5335402
2001-11-05 15:31:59.997 50178.0 21.0 20899 2.4008613
2001-12-10 17:00:00.000 55266.0 38.0 25114 2.2006052
2002-01-03 17:00:00.000 40322.0 51.0 18649 2.1620376
2002-02-25 17:00:00.000 86338.0 24.0 39266 2.1987979
2002-08-15 06:11:00.000 296085.0 166.0 124526 2.3776772
2002-10-07 21:18:59.997 88727.0 826.0 39017 2.2740018
2002-12-17 16:59:00.000 127671.0 6.0 53314 2.3946545
2003-01-16 07:15:00.000 62206.0 71.0 24604 2.5281854
2003-01-21 07:15:00.000 8287.0 43.0 3661 2.2629712
2003-01-27 07:15:00.000 10402.0 68.0 4265 2.4389215
2003-01-31 07:15:00.000 9127.0 73.0 3784 2.4113607
2003-02-05 00:00:00.000 8362.0 327.0 3500 2.3891428
2003-02-10 00:00:00.000 8846.0 262.0 3230 2.7386997
2003-02-14 00:00:00.000 10018.0 51.0 4107 2.4386563
2003-02-20 00:00:00.000 10388.0 91.0 4686 2.2168159
2003-02-26 00:00:00.000 10571.0 69.0 4330 2.4407759
2003-03-03 00:00:00.000 10476.0 261.0 4423 2.3679929
2003-03-06 00:00:00.000 8858.0 594.0 3183 2.7829092
2003-04-02 00:00:00.000 57681.0 275.0 38622 1.4934366
2003-04-05 00:00:00.000 10539.0 29.0 8776 1.2008888
2003-04-09 00:00:00.000 9880.0 1324.0 7193 1.3735576
2003-04-12 00:00:00.000 8953.0 195.0 7737 1.1571668
2003-04-16 00:00:00.000 8385.0 177.0 7154 1.1719078
2003-04-21 00:00:00.000 8920.0 173.0 7756 1.1500773
2003-04-24 00:00:00.000 8563.0 156.0 7320 1.169649
2003-04-29 00:00:00.000 8462.0 137.0 7414 1.1412003
2003-05-02 00:00:00.000 9625.0 140.0 8363 1.1509027
2003-05-06 00:00:00.000 8208.0 904.0 6557 1.251792
2003-05-09 00:00:00.000 9211.0 119.0 7986 1.1533934
2003-05-19 00:00:00.000 19623.0 123.0 17290 1.1348679
2003-05-22 00:00:00.000 9568.0 246.0 8357 1.1449084
2003-05-28 00:00:00.000 9599.0 169.0 8553 1.1221651
2003-06-02 00:00:00.000 10937.0 174.0 9599 1.1393895
2003-07-11 00:00:00.000 99592.0 999.0 83573 1.1916767
2003-07-29 00:00:00.000 42434.0 111.0 33918 1.2510761
2003-08-21 00:00:00.000 59580.0 323.0 50756 1.1738282
2003-09-12 00:00:00.000 51779.0 1407.0 44298 1.1688789
2003-09-25 00:00:00.000 30655.0 255.0 26924 1.138533
2003-10-12 00:00:00.000 44573.0 968.0 37746 1.1808668
2003-10-28 00:00:00.000 38358.0 532.0 32689 1.1734222
2003-11-11 00:00:00.000 35158.0 145.0 28124 1.2500622
2003-12-04 00:00:00.000 61304.0 787.0 52882 1.1592383
2003-12-18 00:00:00.000 44462.0 221.0 39493 1.1257913
2004-01-06 00:00:00.000 56617.0 998.0 49471 1.1444252
2004-02-04 00:00:00.000 96694.0 537.0 83182 1.162425
2004-03-05 00:00:00.000 90850.0 716.0 78693 1.1544864
2004-03-23 00:00:00.000 48969.0 125.0 43450 1.1270195
2004-07-05 00:00:00.000 301725.0 1405.0 258824 1.1657491
2004-08-06 00:00:00.000 95079.0 1419.0 75445 1.2602259
2004-09-03 00:00:00.000 88056.0 193.0 68403 1.2873119
2004-09-23 01:30:12.997 57515.0 8.0 42891 1.3409261
2004-10-11 00:00:00.000 57204.0 116.0 40241 1.4215
2004-10-15 00:00:00.000 17702.0 186.0 12774 1.3856752
2004-10-19 00:00:00.000 9556.0 125.0 7305 1.3079661
2004-10-21 00:00:00.000 8898.0 133.0 6299 1.4126052
2004-10-25 00:00:00.000 8878.0 104.0 6372 1.3930645
2004-10-27 00:00:00.000 11904.0 252.0 6056 1.9656539
2004-10-29 00:00:00.000 8866.0 99.0 6551 1.3533812
2004-11-02 15:22:47.997 12287.0 1.0 9791 1.2547998
2004-11-05 13:16:50.997 12287.0 1.0 10013 1.2269822
2004-11-09 23:52:48.000 12284.0 4.0 9200 1.3352174
2004-11-12 17:17:59.997 12287.0 1.0 9360 1.3127136
2004-11-22 06:58:06.997 24575.0 1.0 19742 1.244745
2004-11-25 01:57:00.000 12287.0 1.0 8822 1.392768
2004-11-30 21:34:59.997 12287.0 1.0 9128 1.3459306
2004-12-03 13:21:24.000 12287.0 1.0 9085 1.3523003
2004-12-07 04:05:21.000 12285.0 5.0 9488 1.2947934
2004-12-09 13:25:00.000 12285.0 5.0 8993 1.3659106
2004-12-13 07:21:46.000 12282.0 10.0 9461 1.2981714
2004-12-15 18:41:23.000 12287.0 2.0 9112 1.3482937
2005-02-04 14:41:36.997 178768.0 58.0 133439 1.3396883
2005-02-23 00:00:00.000 51107.0 29.0 38624 1.3231586
2005-03-10 23:06:17.997 50891.0 24.0 38479 1.3225312
2005-03-28 00:00:00.000 45509.0 32.0 34203 1.3305169
2005-04-13 09:50:34.000 58778.0 19.0 43687 1.3454038
2005-06-08 09:46:43.997 162983.0 25.0 121508 1.3413246
2005-08-08 09:37:29.000 197467.0 20.0 143462 1.3764411
2005-08-24 11:21:37.997 57393.0 5.0 42770 1.3418672
2005-09-11 13:54:05.997 53729.0 5.0 39527 1.3592987
2005-11-08 00:00:00.000 193537.0 69.0 136906 1.4136385
2005-11-22 00:00:00.000 55031.0 33.0 38197 1.4407152
2005-12-05 00:00:00.000 40371.0 77.0 28082 1.4376112
2005-12-22 12:40:59.997 75170.0 3.0 52523 1.4311825
2006-03-02 00:00:00.000 239709.0 42.0 170405 1.4066935
2006-03-04 06:26:36.997 9639.0 23.0 6470 1.489799
2006-03-12 10:02:43.000 21993.0 1.0 16086 1.3672137
2006-03-15 00:00:00.000 8774.0 40.0 6687 1.3119019
2006-04-03 00:00:00.000 69570.0 31.0 46495 1.4962578
2006-04-04 00:00:00.000 8743.0 28.0 4606 1.8977643
2006-04-04 13:53:00.997 12284.0 6.0 3401 3.6108172
2006-04-05 00:00:00.000 10794.0 29.0 3438 3.139616
2006-04-06 00:00:00.000 9413.0 45.0 5001 1.8818473
2006-04-10 00:00:00.000 11058.0 30.0 7865 1.4059758
2006-04-14 00:00:00.000 23183.0 38.0 16281 1.4238423
2006-04-18 00:00:00.000 9898.0 37.0 7258 1.3635488
2006-04-21 03:19:31.000 16561.0 26.0 11848 1.3976707
2006-04-25 14:48:00.000 12287.0 3.0 8553 1.436572
2006-04-27 13:37:49.000 9793.0 96.0 7203 1.3593837
2006-05-02 00:00:00.000 11426.0 30.0 8135 1.4043757
2006-05-04 05:28:36.000 12277.0 22.0 8806 1.3940048
2006-06-08 00:00:00.000 123695.0 33.0 89478 1.3824068
2006-06-16 00:00:00.000 35327.0 37.0 24539 1.4396267
2006-06-29 00:00:00.000 48433.0 40.0 35226 1.3748829
2006-07-14 00:00:00.000 62915.0 57.0 44859 1.4024744
2006-08-10 00:00:00.000 106281.0 36.0 75810 1.401939
2006-08-17 00:00:00.000 25345.0 81.0 18123 1.398422
2006-08-28 00:00:00.000 40947.0 38.0 27573 1.4850397
2006-09-11 09:00:00.000 52187.0 15913.0 36698 1.4220666
2006-09-25 00:00:00.000 52902.0 30.0 37210 1.4216764
2006-10-06 00:00:00.000 54534.0 31.0 38244 1.4259119
2006-10-11 13:29:40.997 16380.0 5.0 12503 1.3100855
2006-11-29 00:00:00.000 197522.0 27.0 138746 1.423623
2006-12-01 00:00:00.000 10584.0 24.0 7602 1.3920821
2007-01-02 00:00:00.000 141284.0 34.0 101246 1.3954526
2007-01-12 02:57:03.997 60416.0 23.0 41700 1.4488249
2007-02-13 00:00:00.000 156270.0 75.0 109875 1.4222525
2007-02-16 00:00:00.000 17770.0 38.0 12325 1.441668
2007-03-05 12:23:00.000 73763.0 3.0 51503 1.43218
2007-03-08 04:11:49.997 16407.0 22.0 11428 1.4355587
2007-03-26 09:10:43.000 76336.0 20.0 53687 1.4218712
2007-04-05 12:31:28.000 64126.0 24.0 40172 1.5962859
2007-04-07 01:11:22.000 9244.0 28.0 6657 1.388405
2007-04-10 00:00:00.000 8924.0 38.0 6140 1.4531835
2007-04-24 21:01:00.000 73487.0 6.0 51689 1.421687
2007-04-26 09:01:48.997 9584.0 25.0 6650 1.441203
2007-04-28 04:09:21.000 9801.0 27.0 7037 1.3925831
2007-05-01 12:55:00.000 8781.0 26.0 6012 1.460336
2007-05-03 00:00:00.000 10570.0 53.0 7298 1.4481436
2007-05-04 21:49:27.000 12287.0 1.0 8680 1.415553
2007-05-08 06:06:45.997 8202.0 27.0 5511 1.4880261
2007-05-10 00:00:00.000 10920.0 49.0 7973 1.3696225
2007-05-12 00:44:10.000 11375.0 27.0 8223 1.3833151
2007-05-15 10:51:50.000 9453.0 27.0 6516 1.4507366
2007-05-18 08:44:36.997 17930.0 27.0 12651 1.4172792
2007-05-22 00:00:00.000 10089.0 74.0 7260 1.3894781
2007-05-23 21:07:38.000 12286.0 3.0 8604 1.4279405
2007-05-26 03:46:02.000 12287.0 6.0 8545 1.4377487
2007-05-30 21:24:29.997 12287.0 1.0 8663 1.4183308
2007-06-01 18:37:16.000 12287.0 1.0 8401 1.4623899
2007-06-05 00:00:00.000 9255.0 52.0 6491 1.4256008
2007-06-08 22:18:40.000 24574.0 3.0 17047 1.4415439
2007-06-12 09:42:14.997 9550.0 31.0 6410 1.4896272
9200-12-08 09:49:59.997 64286.0 1.0 45408 1.4157417

(150 row(s) affected)

What can I do to get SQL to use this index?

View 4 Replies View Related

FailParentOnFailure And MaxErrorCount - Not Functioning As I Would Expect

Mar 31, 2008

I have a package that executes a number of tasks includng executing other packages. In one of the sub-packages, I am looping through a directory, processing files in that directory, and copying the files to another directory after completion using a for each file enumerator and file system task. The file system task has a failure precedence constraint leaving it going into a script task which simply pops up a message box saying that an error occurred.

What I am trying to do is to allow the sub package (and parent package) to continue execution if there is an error during the file system task. This question really is unrelated to the file system task specifically... in general, how can an error be ignored and execution not stop?

On the file system task, I've set MaxErrorCount = 0 and FailParentOnFailure and FailPackageOnFailure are set to False. With MaxErrorCount = 0, the file system task itself does not fail but its parent container (the for each file enumerator) does. This failure then propogates all the way up to the parent package and execution stops. I have gotten around this by setting MaxErrorCount = 0 also on the for each file enumerator, the execute package task, and all its ancestors going all the way up to the root of the main package. This works, but maintaining this would be a nightmare. Setting MaxErrorCount = 0 and FailParentOnFailure = False at the point only where I expect the error seems like it should be enough but it obviously is not. What am I missing here?

View 5 Replies View Related

FTP Task - StopOnFailure Not Working As I Expect?

Dec 8, 2006

Hi

I'm using an FTP task in a loop to download files from a WAN based FTP server. I've got a script to generate the name of the file I require and place into a variable. Problem is sometimes some of the remote files haven't been published so the FTP component errors and the package fails.

I tried setting StopOnFailure to False - all I get is the following errors[FTP Task] Error: File represented by "User::RemotePath" does not exist.
[FTP Task] Error: Attempt to read message string for 0x80020918 failed with error 0xc02090f3. Make sure all message related files are registered.


What I want to do is ignore the error and perform the next loop iteration

Is this a bug, or am I missing something

Dave

View 7 Replies View Related

Service Broker Doesn't Produce What I Expect [Please Read]

Aug 4, 2006

Hi,

I made a simple service broker code that is:

-- step 1: Enable Broker

use master

alter database AdventureWorks

set enable_broker

go



-- step 2: prepare

use AdventureWorks

go

create schema CustomerService

go

create schema EmailService

go



-- step 3: Message Type

create message type [//AdventureWorks/Sales/CustomerDetails]

validation = well_formed_xml

go



-- step 4: Contract

create contract [//AdventureWorks/Sales/SendCustomerDetails]

(

[//AdventureWorks/Sales/CustomerDetails] sent by initiator

)

go



-- step 5: Queue

create queue CustomerService.NewCustomerQueue

go

create queue EmailService.NewCustomerEmailQueue

go



-- step 6: Service

create service [//AdventureWorks/Sales/CustomerService]

on queue CustomerService.NewCustomerQueue

go

create service [//AdventureWorks/Sales/EmailService]

on queue EmailService.NewCustomerEmailQueue

(

[//AdventureWorks/Sales/SendCustomerDetails]

)

go



-- step 7:

create procedure CustomerService.proc_SendMessage

(

@firstName nvarchar(50)

,@lastName nvarchar(50)

,@emailAddress nvarchar(200)

)

as

-- sending a message

declare @message nvarchar(max)

set @message = nchar(0xFEFF)

+ '<Customer>'

+ '<CustomerName>' + @firstName + ' ' + @lastName + '</CustomerName>'

+ '<EmailAddress>' + @emailAddress + '</EmailAddress>'

+ '</Customer>'

declare @conversationHandle uniqueidentifier

begin dialog conversation @conversationHandle

from service [//AdventureWorks/Sales/CustomerService]

to service '//AdventureWorks/Sales/EmailService'

on contract [//AdventureWorks/Sales/SendCustomerDetails]

;send on conversation @conversationHandle

message type [//AdventureWorks/Sales/CustomerDetails]

(

@message

)

go



create procedure CustomerService.proc_ReceiveMessage

as

-- receiving a message

declare @conversationHandle uniqueidentifier, @messageTypeName nvarchar(256)

;receive top(1)

@conversationHandle = conversation_handle

,@messageTypeName = message_type_name

from CustomerService.NewCustomerQueue

if @@rowcount = 0

begin

print 'No further message found in CustomerService.NewCustomerQueue'

end

go

exec CustomerService.proc_SendMessage 'Bishoy','George','bishoy@bishoy.com'

exec CustomerService.proc_ReceiveMessage



--------------------------------------------------------------------------------------------------------------------------

Now the problem is:

when I execute the 2 procedures I receive:
(0 row(s) affected)
No further message found in CustomerService.NewCustomerQueue



Why doesn't the broker send the message?

Is there any needed preparing should I have done first?



Thank you and best regards.

View 7 Replies View Related

Full Text Search Indexing HTML - Does The Filter Expect Certain Tags To Be Present As Standard?

Jul 10, 2007

Hi, I was wondering if any SQL Server gurus out there could help me...I
have a table which contains text resources for my application. The text
resources are multi-lingual so I've read that if I add a html language
indicator meta tag e.g.<META NAME="MS.LOCALE" CONTENT="ES">and
store the text in a varbinary column with a supporting Document Type
column containing ".html" of varchar(5) then the full text index
service should be intelligent about the language word breakers it
applies when indexing the text. (I hope this is correct technique for
best multi-lingual support in a single table?)However, when I come to query this data the results always return 0 rows (no errors are encountered). e.g.DECLARE @SearchWord nvarchar(256)SET @SearchWord = 'search' -- Yes, this word is definitely present in my resources.SELECT * FROM Resource WHERE CONTAINS(Document, @SearchWord)I'm a little puzzled as Full Text search is working fine on another table that employs an nvarchar column (just plain text, no html).Does the filter used for full text indexing of html expect certain tags to be present as standard? E.g. <html> and <body> tags? At present the data I have stored might look like this (no html or body wrapping tags):Example record 1 data: <META NAME="MS.LOCALE" CONTENT="EN">Search for keywords:Example record 2 data: <META NAME="MS.LOCALE" CONTENT="EN">Sorry no results were found for your search.etc.Any pointers / suggestions would be greatly appreciated. Cheers,Gavin.UPDATE: I have tried wrapping the text in more usual html tags and re-built the full text index but I still never get any rows returned for my query results. Example of content wrapping tried - <HTML><HEAD><META NAME="MS.LOCALE" CONTENT="EN"></HEAD><BODY>Test text.</BODY></HTML>I've also tried stripping all html tags from the content and set the Document Type column = .txt but I still get no rows returned?!? 

View 1 Replies View Related

Full Text Search Indexing HTML - Does The Filter Expect Certain Tags To Be Present As Standard?

Jul 11, 2007

Hi, I was wondering if any SQL Server gurus out there could help me...

I have a table which contains text resources for my application. The text resources are multi-lingual so I've read that if I add a html language indicator meta tag e.g.
<META NAME="MS.LOCALE" CONTENT="ES">
and store the text in a varbinary column with a supporting Document Type column containing ".html" of varchar(5) then the full text index service should be intelligent about the language word breakers it applies when indexing the text. (I hope this is correct technique for best multi-lingual support in a single table?)

However, when I come to query this data the results always return 0 rows (no errors are encountered). e.g.
DECLARE @SearchWord nvarchar(256)
SET @SearchWord = 'search' -- Yes, this word is definitely present in my resources.
SELECT * FROM Resource WHERE CONTAINS(Document, @SearchWord)

I'm a little puzzled as Full Text search is working fine on another table that employs an nvarchar column (just plain text, no html).

Does the filter used for full text indexing of html expect certain tags to be present as standard? E.g. <html> and <body> tags? At present the data I have stored might look like this (no html or body wrapping tags):

Example record 1 data: <META NAME="MS.LOCALE" CONTENT="EN">Search for keywords:

Example record 2 data: <META NAME="MS.LOCALE" CONTENT="EN">Sorry no results were found for your search.

etc.

Any pointers / suggestions would be greatly appreciated. Cheers,
Gavin.

UPDATE: I have tried wrapping the text in more usual html tags and re-built the full text index but I still never get any rows returned for my query results. Example of content wrapping tried - <HTML><HEAD><META NAME="MS.LOCALE" CONTENT="EN"></HEAD><BODY>Test text.</BODY></HTML>

I've also tried stripping all html tags from the content and set the Document Type column = .txt but I still get no rows returned?!?

View 1 Replies View Related

SqlCONNECTION

Jul 27, 2006

Public Conn As New SqlConnection("Data Source=localhost;Initial Catalog=tblUsers;UID=XXXX;pwd=XXXX")Public Conn As New SqlConnection("Data Source=XX.XXX.XX.XXX;Initial Catalog=tblUsers;UID=XXXX;pwd=XXXX")
This two commands are in my application.  I switch between the two so I can test my application.
When I put my application on the server, I use the localhost SQLCONNECTION.  The other is commented out.  However, the application continues to connect to the server with the address that is commented out.
THIS IS VERY FRUSTRATING...  HELP!!!!

View 1 Replies View Related

SqlConnection ???????

Oct 2, 2006

Hi, Someone can explain to me what happend in this situation...i have this and want to call a procedure with connection parameters protected void Button1_Click(object sender, EventArgs e)
{

SqlConnection edo = new SqlConnection();
edo.ConnectionString = "server=myserver; uid=admin; pwd=; " +
"database=name1";
SqlCommand com = edo.CreateCommand();
com.CommandType = CommandType.Text;
My_proc(edo, com);
}
protected void My_proc(SqlConnection edo , SqlCommand com)
{
try
{edo.Open();
}
catch{}
finally{ edo.close();}
}

Well what happend with the SqlCommand and SqlConnection when return to Button_Click() Are they alive? Can be used in Buton_Click like parameters for another procedure? or i have to create it again?Thx in advance..                 

View 1 Replies View Related

Sqlconnection

Oct 16, 2006

please help me !!!?I have a problem with sqlconnection definition when I add the sqlconnection from toolbox :like this: Imports System.Data.SqlClientPartial Class _Default    Inherits System.Web.UI.Page    Private Sub InitializeComponent()        Me.sqlConnection1 = New System.Data.SqlClient.SqlConnection        Me.sqlConnection1.ConnectionString = "Data Source=server;Initial Catalog=masterstd;User ID=sa"        Me.sqlConnection1.FireInfoMessageEventOnUserErrors = False    End Sub    Private WithEvents sqlConnection1 As System.Data.SqlClient.SqlConnection    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load        If Not IsPostBack Then            Dim cmduniversity As SqlCommand            Dim dtruniversity As SqlDataReader            cmduniversity = New SqlCommand("select * from university", sqlConnection1)            sqlConnection1.Open()            dtruniversity = cmduniversity.ExecuteReader            dtruniversity.Close()            sqlConnection1.Close()        End If    End SubEnd Classin the sqlconnection.open the nullrefrence exception occures butwhen i define myself this exception dosn't occure.like this:   Imports System.Data.SqlClientPartial Class _Default    Inherits System.Web.UI.Page    Private Sub InitializeComponent()       End Sub    Private WithEvents sqlConnection1 As System.Data.SqlClient.SqlConnection    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load        If Not IsPostBack Then            sqlConnection1 = New SqlConnection            sqlConnection1.ConnectionString = "Data Source=server;Initial Catalog=masterstd;User ID=sa"            sqlConnection1.FireInfoMessageEventOnUserErrors = False            Dim cmduniversity As SqlCommand            Dim dtruniversity As SqlDataReader            cmduniversity = New SqlCommand("select * from university", sqlConnection1)            sqlConnection1.Open()            dtruniversity = cmduniversity.ExecuteReader            dtruniversity.Close()            sqlConnection1.Close()        End If    End Subwhere is the problem?

View 2 Replies View Related

SqlConnection

Apr 28, 2007

 Can someone help me out? I am trying to establish a SQL server connection in my C# code. My C# code crasheds though. Can someone tell me what Iam doing wrong? Here is the C# code:
 
    SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["TheDividerConnectionString"]);
 Here is the connection string as defined in the web.config file:
 <connectionStrings>  <add name="TheDividerConnectionString" connectionString="Data Source=BVCOMPUTERSQLEXPRESS;Initial Catalog=TheDivider;Integrated Security=True"   providerName="System.Data.SqlClient" /> </connectionStrings>
 

View 21 Replies View Related

Sqlconnection

Jun 11, 2007

is their any code which can check my project for any connections which  are open and never closed.
frm 1.1,sql server 2000

View 1 Replies View Related

Sqlconnection

Jan 24, 2008

Would anyone ahve any ideas why when i debug this code, it stops and freezes at cn.open(); A raw sql query against the DB works in this format.
int top=10;SqlConnection cn = new SqlConnection("Data Source=blah;Initial Catalog=blah;Integrated Security=blah");
SqlCommand cmd = new SqlCommand("SELECT DISTINCT TOP (@nrows) [CustNu] FROM [Customer] WHERE [CustNu] like @term", cn);cmd.Parameters.AddWithValue("nrows", top);cmd.Parameters.AddWithValue("term", prefixText + "%");
 
List <string> suggestions = new List<string>();
cn.Open();

View 5 Replies View Related

Pb With SQLConnection

Mar 13, 2008

 HiI would like to have some help for my problem.I'm trying to retreive the connectionString "MyConnectionString" from app.config using method 1 or 2 to get a connection to my DB (without any success.) --> Partial codepublic SqlConnection GetConnection()        {            // reference to System.Configuration Library is done                   1    SqlConnection Connection = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString);--> thrown NullReferenceException on   Conn.Open();                   2    SqlConnection Connection = new SqlConnection(ConfigurationSettings.AppSettings["MyConnectionString"]);--> thrown InvalidOperationException ConnectionString not initialised            return Connection;        }       public Contest GetContestFromDB()        {            SqlConnection Conn = GetConnection();            Conn.Open(); ->> thrown Exception 1 or 2...Here my app.config :<?xml version="1.0" encoding="utf-8"?><configuration>  <appSettings>    <clear/>    <add key="MyConnectionString" value="Server=.SQLExpress;AttachDbFilename=D:Documents and Settings0xMesdocumentsApp_DataShopperDB.MDF;Database=ShopperDB.MDF;Trusted_Connection=Yes;"></add>  </appSettings>  <connectionStrings>    <clear/>   --> using <clear/> to avoid to load from machine.config    <add name="MyConnectionString" connectionString="Server=.SQLExpress;AttachDbFilename=D:Documents and Settings0xMes documentsApp_DataShopperDB.MDF;Database=ShopperDB.MDF;Trusted_Connection=Yes;"></add>  </connectionStrings></configuration> I'm using Visual Studio 2008 with SQLServer 2005 Express Embedded and WindowsXP SP2 .Have you got any idea ?I'm not able to sleep anymore...And I've test this code in ASP.net with the same ConnectionString in the web.config file and it works !!I'm lost.By the way, thx if ou get an answer  ww4ss

View 2 Replies View Related

SQLConnection

Aug 24, 2004

Hi
I have the next simple code, what do i have to change to match it to SQL?
The code:
Sub Page_Load (Source As Object, E as EventArgs)
dim strConn as string =("Provider=" & "Microsoft.Jet.OLEDB.4.0;" & _
"Data Source =C:webspacesegolforferaforfera.co.ildbguestbook.mdb")

Dim MySQL as string = "SELECT Name, EMail, URL, Comment FROM Guestbook"
Dim MyConn as New OleDBConnection (strConn)
Dim Cmd as New OleDBCommand (MySQL, MyConn)
MyConn.Open ()
rptGuestbook.DataSource = Cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
rptGuestbook.DataBind()
End Sub
Thank's and have a good day.

View 3 Replies View Related

Dynamic Sqlconnection

Jul 17, 2006

I have a database for each of my customers and want to connect to a database depending on who is logged in.
all my users have their database name in the user profile.
how can i use the database name in the user profile to change the initial catalog to connect to aaother database?
 
thanks
 
 

View 6 Replies View Related

SqlConnection And Performance

Nov 16, 2006

Hi there,  I'm not sure if the way I handle SqlConnection in my apps is the most performant one.So my apps use db heavily and there are loads of classes with methods like 1 using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["myConn"].ConnectionString))
2
3 {conn.Open();
4 // more code here
5 }
6
7
 As I use using the connection is closed and the object is disposed when leaving the code block.I know that the connection is taken from a pool and when closed it returns to the pool as though I'm not sure if it is better to have one "global" SqlConnection objectand to use that object for all classes or most of them. What about the ConfigurationManager, doesn't it slow down the performance as well when I'm accessing the ConnectionString value thousands of times?I hope someone can point out the issues.Many thanks in advance, Limbic

View 1 Replies View Related

Sqlconnection Object

Jan 3, 2007

I need some information on sqlconnnection object.  I see it referenced in some exercises, and also displayed in the toolbox on some articles, but I'm running .net 2.0 and I have no sqlconnection in my toolbox, but more importantly, I can not seem to drop the data connection from my database/server explorer to my form to create a sqlconn object.   When I highlight the data connection (in my case it's machinenamesqlexpress.pubs.dbo)  and try to drag it - it immediately goes to a NO icon (that is a circle with a slash thru it) and I can not drop it onto my form.  I can see the database with no problems in explorer.
 I have been able to create a sqlconnection programatically:
Dim sqldatasource1 As SqlConnection = New SqlConnection()
sqldatasource1.ConnectionString = "Data Source=localhostsqlexpress;Initial Catalog=pubs;Integrated Security=True"
but how can I create it on my form??  I would appreciate any help on this matter.
 
(p.s. I am using VWD 2005 and SQLExpress)
 

View 5 Replies View Related

SqlConnection Security

Jul 30, 2007

I have created an aspx page that uses the SqlConnection class to pull data from Microsoft CRM’s database, and we have placed this aspx inside CRM’s directory on the server so that it uses the same integrated security that CRM uses. This works fine on our test environment but on our live environment the Sql connection fails with the exception: "Not associated with a trusted SQL Server connection"
This is probably because our test CRM server has the database on the same machine as the web server, but the live environment has the database and the web server on separate machines.
So my question is how can I create an aspx page that takes the integrated security credentials that the user used to log into the website and uses them to access data from a database on a seperate machine?

View 2 Replies View Related

Re-use Of SqlConnection And SqlCommand ?

Oct 26, 2007

Hi,When using the following controls....System.Data.SqlClient.SqlConnection System.Data.SqlClient.SqlCommandIf I want to change my SQL command and execute the query once again what cleanup do I need to do first?Do I need close and dispose the SqlConnection?Do I need to dispose the SqlCommand?Can I use the SqlConnection for more than one SqlCommand?Thanks,Scott   

View 5 Replies View Related

Problem With SQLConnection

Dec 18, 2007

I am working on a set of webforms that insert user data into a set of db tables. 
I set up a test of an approach using northwind and I'm having trouble getting the insert to work.   When I open the form, input the name and phone, and submit there is no error, but no record inserted into the Shippers table. 
You can see one of my approaches in the ASPX code.  I don't like having to do the select in order to do the insert -- so that's commented off. 
I'm stuck.  Thoughts about what I'm missing appreciated...
 
Ray
 ASPX code.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default66a.aspx.cs" Inherits="pages_audit_Default66a" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server"><title>Untitled Page</title>
</head><body>
<form id="form1" runat="server">
CompanyName:
<asp:textbox id="txtCompanyName" runat="server" /><br />
Phone:<asp:textbox id="txtPhone" runat="server" /><br />
<br />
<asp:button id="btnSubmit" runat="server" text="Submit" onclick="btnSubmit_Click" />
<br />
<br />
<br />
<br />
<asp:Label ID="awesomelbl" runat="server" Text="Label"></asp:Label><br />
<br />
<!--
<asp:sqldatasource id="SqlDataSource1" runat="server" connectionstring="<%$ ConnectionStrings:NorthwindConnectionString %>"
insertcommand="INSERT INTO Shippers(CompanyName, Phone) VALUES (@CompanyName, @Phone)" ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM [Shippers]">
<insertparameters>
<asp:controlparameter controlid="txtCompanyName" name="CompanyName" />
<asp:controlparameter controlid="txtPhone" name="Phone" />
</insertparameters>
</asp:sqldatasource>
--></form>
</body>
</html>
c Sharp code
using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.Sql;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class pages_audit_Default66a : System.Web.UI.Page
{protected void Page_Load(object sender, EventArgs e)
{
}protected void btnSubmit_Click(object sender, EventArgs e)
{SqlConnection con = new SqlConnection("Data Source=Chilibowl;Trusted_Connection=yes;DataBase=Northwind");
SqlCommand cmd = new SqlCommand("INSERT INTO [Shippers] ([CompanyName], [Phone]) VALUES (@CompanyName, @Phone)");SqlParameter cnameparam = new SqlParameter("@CompanyName", txtCompanyName.Text); SqlParameter phnparam = new SqlParameter("@Phone", txtPhone.Text);
cmd.Parameters.Add(cnameparam);
cmd.Parameters.Add(phnparam);
try
{
con.Open();if (cmd.ExecuteNonQuery() > 0)awesomelbl.Text = "successful insert";
}
catch
{
//handel
}
finally
{
con.Close();
}
}
}
 

View 2 Replies View Related

Please Help Me Error In Sqlconnection

Jan 4, 2008

An error has occurred while establishing a connection to the server.  When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
this problem occured when i rum my program which contain database connection
any one there can help me please?

View 6 Replies View Related

Reusing An SQLconnection

Nov 12, 2003

Hi all,
I am accessing one database a bunch of different times all throughout my code...in various functions and different web pages. Is there a a way to create an sqlconnection that I can access all the time, instead of constanting hardcoding which database to go to? I've tried putting the info in another file and just including it where I want the database to open, but I can't use <!-- #INCLUDE --> inside of the server scripts.
Can anyone help

View 1 Replies View Related

OleDbConnection Vs SqlConnection

Jan 22, 2004

Hi,

How much of a performance difference is there between connecting to SQL Server 2000 using OleDbConnection or using SqlConnection?

The reason I'm asking is I am taking on the task of updating an older program that uses a Access Database to use SQL Server, but it has a Database Utility class that uses OleDbConnection. I'm just debating whether it would be worthwhile to upgrade the class to use the SQL objects rather than Oledb. Program does a lot of update and insert of invidual records, and a few select statements that usually return from 1 to 2000 records up to a maximum of 50,000 records

Thanks

View 2 Replies View Related

SqlConnection Failed Sometimes

Mar 2, 2004

I've an web app with impersonate windows authentication. IIS uses Windows authentication for this app & anonymous authentication is turned off.
This app have connectionString in Web.config where Windows autentication (SSPI) to SQL Server 2000 took place.
Now I've a piece of code:

public class SiteParameters
{
public static SqlConnection Connection
{
get
{
SqlConnection conn;
try
{
conn = new SqlConnection(ConfigurationSettings.AppSettings["connectionString"]);
if(conn.State != ConnectionState.Open)
conn.Open();
}
catch(Exception)
{
conn = null;
}
return conn;
}
}
}

No comments is needed, think...
Now, I'm going to use it in following way:

SqlConnection conn = SiteParameters.Connection;
SqlDataAdapter dta = new SqlDataAdapter();
DataSet ds = new DataSet();

SqlCommand sqlSelect = new SqlCommand("spPlanTransportSelect", conn);
sqlSelect.CommandType =CommandType.StoredProcedure;

dta.SelectCommand = sqlSelect;
dta.Fill(ds, "PlanTransport");

if(conn.State != ConnectionState.Closed)
conn.Close();
return ds;

It looks good & works good... on local machine only :( When I run app locally (doesn't matter if I call it by http://localhost/app, http://127.0.0.1/app or http://10.50.2.51/app I take proper data from database.
But when my buddy from another comp (e.g. 10.50.2.52) uses URL http://10.50.5.51/app he receives an error in line dta.Fill(ds, "PlanTransport");, but in fact conn variable is null & he receives "yellow" screen where is written that NT ANONYMOUS user is trying to log on to database...
It looks strange for me. Any tips?

View 2 Replies View Related

Why My SqlConnection Failed

Jul 10, 2004

I tried connected my web form with SQL server by drag a table from Server Explore onto the WebForm1.aspx. page. It created a sqlConnection1 and a sqlDataadapter object, but theses two objects seem not work. There is nothing displayed on property window and when I right-click sqlDataAdapter there is no "Preview Data", "Configure Data Adapter" and "Gnerate Dataset" items displayed as well.
I used this SQL server on Windows Form, it worked very well. Could anyone please help me figure it out. Thanks!

View 1 Replies View Related

How To Known That Sqlconnection Is Working

Sep 23, 2004

Hello all,
Actually i want to known, is their any method or property in SqlConnection class which will return some value, so that through which we become confirm that connection has established.

Thanks in advance!

View 2 Replies View Related

SqlConnection Problem...Please Help!!

Oct 28, 2004

Hi !!

I have a code that runs from a different machine and a different site and i am facing a problem that i can not log in to the database.I installed SQL Server on my machine and I created a user "fadila" and SQL Server Authentication and the password is "fadil1977" and the database is "otters" and it is installed as tables and stored procedures but there is not data on these tables.

I used the method provided in the code so, i only change the "connStr" in one place rather than in 20 places and my code is as below. Can you please Help me to connect to the database. I Really..Really appreciate it if you help me to solve it as it causeing me a big head-ache and still get the error message "SQL Server does not exist or access denied" .. please help!!!!




Friend Shared ReadOnly Property connStr() As String

Get

Return String.Format( _

"Data Source={0};Initial Catalog=Otters;User ID=fadila;Password=fadil1977", _

DatabaseMachine)

End Get

End Property

View 4 Replies View Related

SQLConnection Control

May 18, 2005

If i use the TimeTracker app from the starter kit suite and I enter my SQL connection in the web.config file it works fine,
 
If i build a simple app with just a sqladapter, sqlconnection and dataset control then enter in the page_load procedure
 
sqlDataAdater1.fill(dataset11)
datagrid1.databind()
It keeps giving my errors see below:  I created a connection with the sqlconnection control and used the same userid and password I used in the time tracker stater kit's web config file which works - I have no idea what is going on
 
*** is it better to create the sqlconnection control first then create the sqladapter or vise versa.
Server Error in '/WebApplication2' Application.


Login failed for user 'IssueTrackerUser'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SqlClient.SqlException: Login failed for user 'IssueTrackerUser'.Source Error:



Line 55: Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Line 56: 'Put user code to initialize the page here
Line 57: SqlDataAdapter1.Fill(DataSet11)
Line 58: DataGrid1.DataBind()
Line 59: Source File: c:inetpubwwwrootWebApplication2WebForm1.aspx.vb    Line: 57 Stack Trace:



[SqlException: Login failed for user 'IssueTrackerUser'.]
System.Data.SqlClient.ConnectionPool.GetConnection(Boolean& isInTransaction)
System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnectionString options, Boolean& isInTransaction)
System.Data.SqlClient.SqlConnection.Open()
System.Data.Common.DbDataAdapter.QuietOpen(IDbConnection connection, ConnectionState& originalState)
System.Data.Common.DbDataAdapter.FillFromCommand(Object data, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
WebApplication2.WebForm1.Page_Load(Object sender, EventArgs e) in c:inetpubwwwrootWebApplication2WebForm1.aspx.vb:57
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()



Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573
 

View 1 Replies View Related

Opening SqlConnection - VB.NET

Sep 8, 2005

I used to use rdo in VB6 and now I'm trying to figure out how to use the SqlDataReader class in VB.NET.  I want to use an ODBC data source to specify the connection info.  I used to give the rdoConnection object a connect string that looked something like this:"DSN=[data source name];UID=[sql server user];PWD=[pwd]"I don't understand the connect string given in all the examples I've found (nor does it seem to work on my system...)
mySqlConnection = New SqlConnection("server=(local)VSdotNET;Trusted_Connection=yes;database=northwind")Does anyone have any ideas?  I'm open to explanations as well as solutions :)Thanks,jdm

View 3 Replies View Related

SqlConnection.Parameters

Jan 19, 2006

Hello,
I've got some questions about SqlConnection.Parameters collection.
1) I tried add parameters and I don't know if following 2 codes are equivalent 
sql.Parameters.Add(new SqlParameter("@FirstName", SqlDbType.NVarChar, 10));sql.Parameters["@FirstName"].Value = firstname;-----sql.Parameters.Add("@FirstName", SqlDbType.NVarChar, 10);sql.Parameters["@FirstName"].Value = firstname;
Is some difference between this codes? Or in second case is created instance of SqlParamater automaticly?
2) I read that Add method is in asp.net 2.0 deprected. And now it uses Addwithvalue method, but when I don't write value of Parameter to the constructor, can (should) I use still Add method? In this case VS doesn't show any warning. VS shows warning only if I use value (object) in constructor.

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved