Showing posts with label msde. Show all posts
Showing posts with label msde. Show all posts

Monday, March 26, 2012

Help with sp_executesql and return parameter

I am trying to use dynamic sql with a return parameter, but with limited success. I am using WebMatrix, vb.net and MSDE to perform this routine. Can someone please clue me in. I have read two fine articles by <a href='http://www.algonet.se/~sommar/dyn-search.html>Erland Sommarskog</a> on dynamic sql using sp_executesql, as well as the somewhat opaque article by Microsoft (262499) on the subject.

While there may be other ways to accomplish this task, I am interested in making it work with dynamic SQL. In production, there will be over 20 parameters coming from the vb.net to the SQL, being driven from user input. Then those same variables will be used to actually retrieve the records to a datagrid.

So with a tip of the cap to Rod Serling, I submit this small code and SQL for your consideration from my Twilight Zone:


Public Function totalrecordsbysql(list as arraylist) as integer
dim RetVal as new integer
dim querystring as string

Dim cn As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("Indiafriend"))
Dim cmd As SqlCommand = New SqlCommand("SimpleDynProfileCount", cn)
cmd.commandtype = commandtype.storedprocedure

dim mydr as SqlDataReader

cmd.Parameters.add("@.TotalRecords",SqlDbType.int).direction=ParameterDirection.Output
cmd.Parameters.add("@.age",sqldbtype.int).value = 18

cn.Open()

try
mydr=cmd.executereader()
catch e as sqlexception
dim err as sqlerror
dim strErrorString as string

for each err in e.Errors
strErrorString += "SqlError: #" & err.Number.ToString () & vbCRLF + err.Message
trace.write("sqlexception",strErrorString)
Next

finally

RetVal = cmd.parameters("@.TotalRecords").value

end try

Return RetVal
cn.close()
End Function


Now here is the stored procedure:

CREATE PROCEDURE SimpleDynProfileCount

@.age int,
@.TotalRecords int output

AS

Declare @.sql nvarchar(4000),
@.paramlist nvarchar(4000)

select @.sql = 'select @.xTotalRecords = count(*) from profile where 1 = 1 '

// RAISERROR(@.sql, 16, 1)

IF @.age > 0
Select @.sql = @.sql + ' AND age > @.xage '

Select @.paramlist = '@.xage int, @.xTotalRecords int output'

Execute sp_executesql @.sql,@.paramlist,@.age,@.xTotalRecords = @.TotalRecords output

select @.TotalRecords
GO


Please note the commented RAISERROR statement. If I uncomment this statement, I will get a return value of 11 records. If I leave it out, I get zero records.
The data is the database should return 11 records, based on the criteria of age > 11Your code works fine for me in Query Analyzer -- with one exception. I needed to change the double forward slashes (//) to double dashes (--) in front of the RAISERROR.

You might also place a SET NOCOUNT ON at the top of your stored procedure. This will suppress the information "xx items selected" messages and will avoid having them returned inadvertently as a resultset.

Terri|||That's what is so strange: I don't receive error messages, just the wrong answer (zero). The double dashes are just artistic license: I didn't remember the comment tag. I just eliminate the line, altogether, in production.|||Try adding SET NOCOUNT ON after your AS at the top of the stored procedure.

Terri|||I have added the statement, but the results are the same. Works fine with the RAISERROR statement, but returns zero without the statement.

I don't want to just leave the RAISERROR statement active. It will come back to haunt me later.

rod|||I have resolved the syntax.

I made a mistake in the vb.net when I used a datareader to retrieve the output value!

Instead of:


mydr=cmd.executereader()

the syntax should be:

cmd.executeNonQuery()

Using this syntax I removed from the Stored Procedure, the RAISERROR statement and the last SELECT @.totalrecords.

After doing all that, everything worked as expected.

-rod

Wednesday, March 21, 2012

Help with relations

I am using MSDE Manager for my database, and I was wondering, if data is entered on one table, IE UserID, shouldnt that same userID pop up in the related column on the foreign table as well?I don't quite see what you're getting at here

Wednesday, March 7, 2012

Help with outer join query please!

I have a MSDE query that includes a "left outer join..." clause. It runs fine in MSDE Query (a 3rd party GUI tool) and produces 12 rows. column 3 has some NULL values (because of the outer join).

But when I use the same query in an ASP.NET page, and display the result in a datagrid, it only displays 7 rows - the rows with the NULL value in column 3 do not display.

Is there a parameter somewhere in datagrid or dataset that I should be setting?

thank you someone!there should be an AllowDbNull afaik|||


private void AddNullAllowedColumn(){
DataColumn myColumn;
myColumn = new DataColumn("classID", System.Type.GetType("System.Int32"));
myColumn.AllowDBNull = true;
// Add the column to a new DataTable.
DataTable myTable;
myTable = new DataTable();
myTable.Columns.Add(myColumn);
}

maybe a foreach (DataColumn column in DataGrid.Columns) { or datatable.
you can specify that.

Monday, February 27, 2012

Help with MSDE Install

Installed MSDE on windowsxp pro.
When computer restarts, icon seen at System Tray.
Click on icon and SQL Server Service Manager.
Server field blank
Services field blank
typed in computername for Server field
select start/continue button.
error message that no service has been selected.
Where did I go wrong?
Walter Wu
Logfile:
2005-06-30 07:26:25.64 server Microsoft SQL Server 2000 - 8.00.760
(Intel X86)
Dec 17 2002 14:22:05
Copyright (c) 1988-2003 Microsoft Corporation
Desktop Engine on Windows NT 5.1 (Build 2600: Service Pack 2)
2005-06-30 07:26:25.64 server Copyright (C) 1988-2002 Microsoft
Corporation.
2005-06-30 07:26:25.64 server All rights reserved.
2005-06-30 07:26:25.64 server Server Process ID is 540.
2005-06-30 07:26:25.64 server Logging SQL Server messages in file
'G:\MSSQL$MYFIRSTSQLSERVER\LOG\ERRORLOG'.
2005-06-30 07:26:25.67 server SQL Server is starting at priority class
'normal'(2 CPUs detected).
2005-06-30 07:26:26.54 server SQL Server configured for thread mode
processing.
2005-06-30 07:26:26.54 server Using dynamic lock allocation. [500] Lock
Blocks, [1000] Lock Owner Blocks.
2005-06-30 07:26:26.70 spid2 Starting up database 'master'.
2005-06-30 07:26:27.07 server Using 'SSNETLIB.DLL' version '8.0.766'.
2005-06-30 07:26:27.07 spid5 Starting up database 'model'.
2005-06-30 07:26:27.10 spid2 Server name is 'MASTER\MYFIRSTSQLSERVER'.
2005-06-30 07:26:27.10 spid2 Skipping startup of clean database id 4
2005-06-30 07:26:27.21 server SQL server listening on Shared Memory.
2005-06-30 07:26:27.25 spid5 Clearing tempdb database.
2005-06-30 07:26:27.67 spid5 Starting up database 'tempdb'.
2005-06-30 07:26:27.75 spid2 Recovery complete.
2005-06-30 07:26:27.75 spid2 SQL global counter collection task is
created.
2005-06-30 07:26:28.57 server SQL Server is ready for client connections
"NoOne" <NoOne@.NoName.com> wrote in message
news:%238pclQQfFHA.268@.TK2MSFTNGP15.phx.gbl...
> Installed MSDE on windowsxp pro.
> When computer restarts, icon seen at System Tray.
> Click on icon and SQL Server Service Manager.
> Server field blank
> Services field blank
> typed in computername for Server field
> select start/continue button.
> error message that no service has been selected.
> Where did I go wrong?
>
> Walter Wu
>
|||hi Walter,
NoOne wrote:
> Installed MSDE on windowsxp pro.
> When computer restarts, icon seen at System Tray.
> Click on icon and SQL Server Service Manager.
> Server field blank
> Services field blank
> typed in computername for Server field
> select start/continue button.
> error message that no service has been selected.
> Where did I go wrong?
>
from your log file, your MSDE is runnig... but you probably installed MSDE
without network protocols support, and this unfortunately can cause the
corresponding instance not to show up in the SQL Server Service Manager, as
reported in http://support.microsoft.com/default...b;EN-US;814132
Andrea Montanari (Microsoft MVP - SQL Server)
http://www.asql.biz/DbaMgr.shtmhttp://italy.mvps.org
DbaMgr2k ver 0.12.0 - DbaMgr ver 0.58.0
(my vb6+sql-dmo little try to provide MS MSDE 1.0 and MSDE 2000 a visual
interface)
-- remove DMO to reply
|||-
/kj
"NoOne" <NoOne@.NoName.com> wrote in message
news:ekke%23fQfFHA.2384@.TK2MSFTNGP15.phx.gbl...[vbcol=seagreen]
> Logfile:
> 2005-06-30 07:26:27.10 spid2 Server name is 'MASTER\MYFIRSTSQLSERVER'.
> "NoOne" <NoOne@.NoName.com> wrote in message
> news:%238pclQQfFHA.268@.TK2MSFTNGP15.phx.gbl...
Trying entering
MASTER\MYFIRSTSQLSERVER
on the server line of SQL Server Manager, wait a painfully long time with
the hour glass, and eventually you should see your services state.
Unfortunately, you'll have to do this everytime as it won't stick. ( Don't
you wish you had shortened that instance name now? ;-) )
/kj
|||Change the instance name and removed the password and it works.
Thanks everyone.
"NoOne" <NoOne@.NoName.com> wrote in message
news:ekke%23fQfFHA.2384@.TK2MSFTNGP15.phx.gbl...
> Logfile:
> 2005-06-30 07:26:25.64 server Microsoft SQL Server 2000 - 8.00.760
> (Intel X86)
> Dec 17 2002 14:22:05
> Copyright (c) 1988-2003 Microsoft Corporation
> Desktop Engine on Windows NT 5.1 (Build 2600: Service Pack 2)
> 2005-06-30 07:26:25.64 server Copyright (C) 1988-2002 Microsoft
> Corporation.
> 2005-06-30 07:26:25.64 server All rights reserved.
> 2005-06-30 07:26:25.64 server Server Process ID is 540.
> 2005-06-30 07:26:25.64 server Logging SQL Server messages in file
> 'G:\MSSQL$MYFIRSTSQLSERVER\LOG\ERRORLOG'.
> 2005-06-30 07:26:25.67 server SQL Server is starting at priority class
> 'normal'(2 CPUs detected).
> 2005-06-30 07:26:26.54 server SQL Server configured for thread mode
> processing.
> 2005-06-30 07:26:26.54 server Using dynamic lock allocation. [500] Lock
> Blocks, [1000] Lock Owner Blocks.
> 2005-06-30 07:26:26.70 spid2 Starting up database 'master'.
> 2005-06-30 07:26:27.07 server Using 'SSNETLIB.DLL' version '8.0.766'.
> 2005-06-30 07:26:27.07 spid5 Starting up database 'model'.
> 2005-06-30 07:26:27.10 spid2 Server name is 'MASTER\MYFIRSTSQLSERVER'.
> 2005-06-30 07:26:27.10 spid2 Skipping startup of clean database id 4
> 2005-06-30 07:26:27.21 server SQL server listening on Shared Memory.
> 2005-06-30 07:26:27.25 spid5 Clearing tempdb database.
> 2005-06-30 07:26:27.67 spid5 Starting up database 'tempdb'.
> 2005-06-30 07:26:27.75 spid2 Recovery complete.
> 2005-06-30 07:26:27.75 spid2 SQL global counter collection task is
> created.
> 2005-06-30 07:26:28.57 server SQL Server is ready for client
> connections
> "NoOne" <NoOne@.NoName.com> wrote in message
> news:%238pclQQfFHA.268@.TK2MSFTNGP15.phx.gbl...
>

Help with MSDE 1.0

Hi everyone!
First I'll expose my problem: I have a crashed disk which I believe had MSDE
1.0 installed (MSSQL7 folder). I had no problems recovering the databases
from backups but there was some DTS's that obviously were in msdb database.
I have the .mdf and .ldf files and I also have a backup but the problem is
that I can't find any disk with that version nor download from Internet, the
version is not available from microsoft downloads anymore. I tried to
recover it with MSDE 2 Release A, but if I try to upload the backup it says
that it was created with other version, and if I just overwrite the msf file
it goes to "suspect" state.
Now, I have two petitions :
1.- Can anybody point me to a place where I can download MSDE 1.0 o tell me
one software app has it included ?
2.- Does somebody know any workaround to recover this data using MSDE 2 Rel
A?
Thanks in advance
Eduardo Martinez O.
Chief of Information Systems
Industria Envasadora de Queretaro, S.A. de C.V.
hi Eduardo,
"Eduardo Martinez" <eduardom@.nospamieqsa.com.mx> ha scritto nel
messaggio news:OCyWNNV2EHA.1192@.tk2msftngp13.phx.gbl
> Hi everyone!
> First I'll expose my problem: I have a crashed disk which I believe
> had MSDE
> 1.0 installed (MSSQL7 folder). I had no problems recovering the
> databases from backups but there was some DTS's that obviously were
> in msdb database. I have the .mdf and .ldf files and I also have a
> backup but the problem is that I can't find any disk with that
> version nor download from Internet, the version is not available from
> microsoft downloads anymore. I tried to recover it with MSDE 2
> Release A, but if I try to upload the backup it says that it was
> created with other version, and if I just overwrite the msf file it
> goes to "suspect" state.
> Now, I have two petitions :
> 1.- Can anybody point me to a place where I can download MSDE 1.0 o
> tell me one software app has it included ?
> 2.- Does somebody know any workaround to recover this data using MSDE
> 2 Rel A?
>
1) don't know how much legal...
http://www.blackberry.net/support/downloads/msde.shtml ... I do think (some
or all) Office 2000 (editions) should contain MSDE 1.0 too...
2) unfortunately not, as msdb database of 7.0 code base can not be restored
on 2000 versions...
Andrea Montanari (Microsoft MVP - SQL Server)
http://www.asql.biz/DbaMgr.shtmhttp://italy.mvps.org
DbaMgr2k ver 0.9.1 - DbaMgr ver 0.55.1
(my vb6+sql-dmo little try to provide MS MSDE 1.0 and MSDE 2000 a visual
interface)
-- remove DMO to reply
|||Thanks a lot, I downloaded from the page you told. I'll just use it to
restore mi backup and send the dts to the new disk.
Eduardo Martinez O.