Showing posts with label back. Show all posts
Showing posts with label back. Show all posts

Sunday, March 25, 2012

Cant get a simple code to work

Can someone please help me fix this. The if statement always runs. I only want it to run if the statement is true and there is a result coming back. If the productID does not have any magazines linking to it, I don't want the If statement to run. Thanks in advance.

ASP.NET code:

If Not Magazine.GetMagazinesForProduct(ProductID) Is Nothing Then
blanklabel.Text = categoryDetails.Spacer
blanklabel.Visible = True
blanklabel2.Text = categoryDetails.Spacer
blanklabel2.Visible = True
magazinerecommendedlabel.Text = "Recommended/Featured in the following magazine(s):"
magazinerecommendedlabel.Visible = True
End If
--------

magazine class:

Public Function GetMagazinesForProduct(ByVal productID As String) As SqlDataReader
Dim connection As New SqlConnection(connectionString)

Dim command As New SqlCommand("GetMagazinesForProduct", connection)
command.CommandType = CommandType.StoredProcedure

command.Parameters.Add("@.ProductID", SqlDbType.VarChar, 50)
command.Parameters("@.ProductID").Value = productID

connection.Open()

Return command.ExecuteReader(CommandBehavior.CloseConnection)
End Function

--------

Stored Procedure:

CREATE PROCEDURE GetMagazinesForProduct
(@.ProductID varchar)
AS
SELECT Magazine.[Name], Magazine.[Issue], Magazine.SmallImagePath
FROM Magazine INNER JOIN MagazineProduct
ON Magazine.MagazineID = MagazineProduct.MagazineID
WHERE MagazineProduct.ProductID = @.ProductID
RETURN
GO

--------How about trying a while instead? I'm not sure of the exact VB syntax, maybe something like this:


dim myReader as Magazine.GetMagazinesForProduct(ProductID)
While myReader .Read()
.. do your stuff
end while
|||for some reason, myReader.Read() always executes FALSE. Why is that?|||It means there's no data in present. Are you positive your stored proc is returning data for the id you are passing to it?

Can't generate script for Triggers using DMO

For some reason, when I try to generate a script for Triggers off of a View
using DMO, I get back garbage like:
?VIEW1
That's the complete text coming back, nothing more. I can see it clearly
using MSEM just fine. Any thoughts?
Lee
Can you post your code, so that we can look into it?
HTH,
Vyas, MVP (SQL Server)
SQL Server Articles and Code Samples @. http://vyaskn.tripod.com/
"Lee Grissom" <lee dot grissom at quest dot com> wrote in message
news:uyVQJqqdFHA.3932@.TK2MSFTNGP12.phx.gbl...
For some reason, when I try to generate a script for Triggers off of a View
using DMO, I get back garbage like:
?VIEW1
That's the complete text coming back, nothing more. I can see it clearly
using MSEM just fine. Any thoughts?
Lee
|||You mean scripting an INSTEAD OF TRIGGER on a VIEW?
GertD@.SQLDev.Net
Please reply only to the newsgroups.
This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use.
Copyright SQLDev.Net 1991-2005 All rights reserved.
"Lee Grissom" <lee dot grissom at quest dot com> wrote in message
news:uyVQJqqdFHA.3932@.TK2MSFTNGP12.phx.gbl...
> For some reason, when I try to generate a script for Triggers off of a
> View using DMO, I get back garbage like:
> ?VIEW1
> That's the complete text coming back, nothing more. I can see it clearly
> using MSEM just fine. Any thoughts?
> --
> Lee
>
|||This works for me:
CREATE TABLE Person
(
SSN char(11) PRIMARY KEY,
Name nvarchar(100),
Address nvarchar(100),
Birthdate datetime
)
go
CREATE TABLE EmployeeTable
(
EmployeeID int PRIMARY KEY,
SSN char(11) UNIQUE,
Department nvarchar(10),
Salary money,
CONSTRAINT FKEmpPer FOREIGN KEY (SSN)
REFERENCES Person (SSN)
)
go
CREATE VIEW Employee AS
SELECT P.SSN as SSN, Name, Address,
Birthdate, EmployeeID, Department, Salary
FROM Person P, EmployeeTable E
WHERE P.SSN = E.SSN
go
CREATE TABLE PersonDuplicates
(
SSN char(11),
Name nvarchar(100),
Address nvarchar(100),
Birthdate datetime,
InsertSNAME nchar(100),
WhenInserted datetime
)
go
CREATE TRIGGER IO_Trig_INS_Employee ON Employee
INSTEAD OF INSERT
AS
BEGIN
SET NOCOUNT ON
-- Check for duplicate Person. If no duplicate, do an insert.
IF (NOT EXISTS (SELECT P.SSN
FROM Person P, inserted I
WHERE P.SSN = I.SSN))
INSERT INTO Person
SELECT SSN,Name,Address,Birthdate
FROM inserted
ELSE
-- Log attempt to insert duplicate Person row in PersonDuplicates table.
INSERT INTO PersonDuplicates
SELECT SSN,Name,Address,Birthdate,SUSER_SNAME(),GETDATE()
FROM inserted
-- Check for duplicate Employee. If no duplicate, do an insert.
IF (NOT EXISTS (SELECT E.SSN
FROM EmployeeTable E, inserted
WHERE E.SSN = inserted.SSN))
INSERT INTO EmployeeTable
SELECT EmployeeID,SSN, Department, Salary
FROM inserted
ELSE
--If duplicate, change to UPDATE so that there will not
--be a duplicate key violation error.
UPDATE EmployeeTable
SET EmployeeID = I.EmployeeID,
Department = I.Department,
Salary = I.Salary
FROM EmployeeTable E, inserted I
WHERE E.SSN = I.SSN
END
go
using System;
using System.Runtime.InteropServices;
using SQLDMO;
namespace SDN
{
class ScriptInsteadOfTrigger
{
[MTAThread]
static void Main(string[] args)
{
try
{
SQLServer2Class server = new SQLServer2Class();
server.LoginSecure = true;
server.Connect("(local)\\sql80", null, null);
Database2 database = (Database2) server.Databases.Item("testdb", "dbo");
View2 view = (View2) database.Views.Item("Employee", "dbo");
Trigger2 trigger = (Trigger2) view.Triggers.Item("IO_Trig_INS_Employee",
"dbo");
SQLDMO_SCRIPT_TYPE scriptType = SQLDMO_SCRIPT_TYPE.SQLDMOScript_Default;
SQLDMO_SCRIPT2_TYPE script2Type =
SQLDMO_SCRIPT2_TYPE.SQLDMOScript2_Default;
string sql = trigger.Script(scriptType, null, script2Type);
server.DisConnect();
}
catch(System.Runtime.InteropServices.COMException ex)
{
Console.WriteLine(ex);
}
catch(System.Exception ex)
{
Console.WriteLine(ex);
}
}
}
}
GertD@.SQLDev.Net
Please reply only to the newsgroups.
This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use.
Copyright SQLDev.Net 1991-2005 All rights reserved.
"Lee Grissom" <lee dot grissom at quest dot com> wrote in message
news:uyVQJqqdFHA.3932@.TK2MSFTNGP12.phx.gbl...
> For some reason, when I try to generate a script for Triggers off of a
> View using DMO, I get back garbage like:
> ?VIEW1
> That's the complete text coming back, nothing more. I can see it clearly
> using MSEM just fine. Any thoughts?
> --
> Lee
>

Monday, March 19, 2012

Can't Divide a count function?

I am trying to divide 2 funcitons by each other and I am coming back with 0 as my result in one of them while I am getting the correct answer in another. The two columns I am trying to pull with functions are:

SELECT

sum(D.PrincipalBal)/sum(L.PrincipalBal)*100 as DelqRatioByBal
, count(D.LoanID)/count(L.LoanID)*100 as DelqRatioByCnt

FROM Loan L

INNER JOIN DelqINFO D on D.LoanID = L.LoanID

I get the correct result back for 'DelqRatioByBal' but I get 0 back for 'DelqRatioByCnt'

Any suggestons?

that because you are doing an integer division

take a look at this

select 1/2 --int division
select (1.00*1)/2

go
--
SELECT

sum(D.PrincipalBal)/sum(L.PrincipalBal)*100 as DelqRatioByBal
, (1.00*count(D.LoanID))/count(L.LoanID)*100 as DelqRatioByCnt

--

any number multiplied by 1 = the number

|||Thanks Joey, worked well. I appreciate it.

Thursday, February 16, 2012

Can''t connect to SQL Express or SQL 2005 from C# web app and IIS

Hi all,

I'm new to this forum and haven't worked with SQL Server for a couple of years. Now it seems I'm getting back into it. I have SQL Express and SQL 2005 installed on an XP sp2 machine with IIS 5.1. I have a C#/ASP.NET web app in Visual Studio 2005 that keeps getting an error on attempting to connect (SqlConnection object). It's a generic error saying a probable cause is SQL Express default setup not allowing remote connections. Remote connections are turned on for both TCP and UDP. I can connect from within a small C# windows application using the same uid and pwd, so I suspect it's something related to IIS talking to SQLExpress. I would appreciate any help on other things to check. I am also fairly new to using IIS in the development environment.

Thanks

It could be because you didn't specify the instance name when you tried to connect from the C# app? It could also be that SQLBrowser isn't running.

Hope that helps,

John

|||

This is because SQL Server 2005 Express Edition does not accepts remote connections by default:

How to: Enable Network Access During Installation of SQL Server 2005 Express Edition

|||

Thanks John,

Yes, I specified the instance name and verified SQLBrowser is running. COnnection string = "Server=BUTTERFLY\SQLExpress; Initial Catalog=catalog; uid=username; pwd=password;

|||

Ronald,

Thanks for pointing me to this information. It didn't actually solve my dilemma, but it did get the juices flowing. This is related to a project I inherited and upgraded from .NET 1.1 to 2.0. The sql connection string referenced a property for "server=", changing this to "data source=" allowed the connection to open properly. I am reading the links you pointed and they are very helpful. Thanks

Can''t connect to SQL Express or SQL 2005 from C# web app and IIS

Hi all,

I'm new to this forum and haven't worked with SQL Server for a couple of years. Now it seems I'm getting back into it. I have SQL Express and SQL 2005 installed on an XP sp2 machine with IIS 5.1. I have a C#/ASP.NET web app in Visual Studio 2005 that keeps getting an error on attempting to connect (SqlConnection object). It's a generic error saying a probable cause is SQL Express default setup not allowing remote connections. Remote connections are turned on for both TCP and UDP. I can connect from within a small C# windows application using the same uid and pwd, so I suspect it's something related to IIS talking to SQLExpress. I would appreciate any help on other things to check. I am also fairly new to using IIS in the development environment.

Thanks

It could be because you didn't specify the instance name when you tried to connect from the C# app? It could also be that SQLBrowser isn't running.

Hope that helps,

John

|||

This is because SQL Server 2005 Express Edition does not accepts remote connections by default:

How to: Enable Network Access During Installation of SQL Server 2005 Express Edition

|||

Thanks John,

Yes, I specified the instance name and verified SQLBrowser is running. COnnection string = "Server=BUTTERFLY\SQLExpress; Initial Catalog=catalog; uid=username; pwd=password;

|||

Ronald,

Thanks for pointing me to this information. It didn't actually solve my dilemma, but it did get the juices flowing. This is related to a project I inherited and upgraded from .NET 1.1 to 2.0. The sql connection string referenced a property for "server=", changing this to "data source=" allowed the connection to open properly. I am reading the links you pointed and they are very helpful. Thanks

Can''t connect to SQL Express or SQL 2005 from C# web app and IIS

Hi all,

I'm new to this forum and haven't worked with SQL Server for a couple of years. Now it seems I'm getting back into it. I have SQL Express and SQL 2005 installed on an XP sp2 machine with IIS 5.1. I have a C#/ASP.NET web app in Visual Studio 2005 that keeps getting an error on attempting to connect (SqlConnection object). It's a generic error saying a probable cause is SQL Express default setup not allowing remote connections. Remote connections are turned on for both TCP and UDP. I can connect from within a small C# windows application using the same uid and pwd, so I suspect it's something related to IIS talking to SQLExpress. I would appreciate any help on other things to check. I am also fairly new to using IIS in the development environment.

Thanks

It could be because you didn't specify the instance name when you tried to connect from the C# app? It could also be that SQLBrowser isn't running.

Hope that helps,

John

|||

This is because SQL Server 2005 Express Edition does not accepts remote connections by default:

How to: Enable Network Access During Installation of SQL Server 2005 Express Edition

|||

Thanks John,

Yes, I specified the instance name and verified SQLBrowser is running. COnnection string = "Server=BUTTERFLY\SQLExpress; Initial Catalog=catalog; uid=username; pwd=password;

|||

Ronald,

Thanks for pointing me to this information. It didn't actually solve my dilemma, but it did get the juices flowing. This is related to a project I inherited and upgraded from .NET 1.1 to 2.0. The sql connection string referenced a property for "server=", changing this to "data source=" allowed the connection to open properly. I am reading the links you pointed and they are very helpful. Thanks

Can''t connect to SQL Express or SQL 2005 from C# web app and IIS

Hi all,

I'm new to this forum and haven't worked with SQL Server for a couple of years. Now it seems I'm getting back into it. I have SQL Express and SQL 2005 installed on an XP sp2 machine with IIS 5.1. I have a C#/ASP.NET web app in Visual Studio 2005 that keeps getting an error on attempting to connect (SqlConnection object). It's a generic error saying a probable cause is SQL Express default setup not allowing remote connections. Remote connections are turned on for both TCP and UDP. I can connect from within a small C# windows application using the same uid and pwd, so I suspect it's something related to IIS talking to SQLExpress. I would appreciate any help on other things to check. I am also fairly new to using IIS in the development environment.

Thanks

It could be because you didn't specify the instance name when you tried to connect from the C# app? It could also be that SQLBrowser isn't running.

Hope that helps,

John

|||

This is because SQL Server 2005 Express Edition does not accepts remote connections by default:

How to: Enable Network Access During Installation of SQL Server 2005 Express Edition

|||

Thanks John,

Yes, I specified the instance name and verified SQLBrowser is running. COnnection string = "Server=BUTTERFLY\SQLExpress; Initial Catalog=catalog; uid=username; pwd=password;

|||

Ronald,

Thanks for pointing me to this information. It didn't actually solve my dilemma, but it did get the juices flowing. This is related to a project I inherited and upgraded from .NET 1.1 to 2.0. The sql connection string referenced a property for "server=", changing this to "data source=" allowed the connection to open properly. I am reading the links you pointed and they are very helpful. Thanks

Sunday, February 12, 2012

can''t connect to local user instance

Just when I think I have this stuff figured out, it bites me back everytime.

I'm

trying to deploy an mdf out to a different machine, and attached to it with local user instance. I connect without problem from my development

machine with a local user instance, which also has Express Manager resident,

and I can connect to a server instance without problem.

What I can't do is

copy the .mdf database over to another workstation, which has Sql Native

Client installed, and connect to the database using a local user

instance! I can connect to a server instance without problem from this

other workstation. Here's my connect string for local user instance

that works fine from my dev machine:

Provider=SQLNCLI.1;Persist

Security Info=False;Integrated Security=SSPI;Data

Source=.\sqlexpress;AttachDBFileName=<full path_name and mdf

filename>;User Instance=true;

The error I get upon trying to connect with other stations is:

Error -2147467259
Database not found or cound not connect to database

I've

tried this every way I know how. I've copied the database from my dev

machine both with and without having detached the database from the

local instance. I've tried detaching from a server instance and copying

the file over. Nothing works, and I've done this before! What gives with this thing?

Rick

Hi,

is SQL Server Service allowed to access the datafiles ?

Jens K. Suessmeyer.


http://www.sqlserver2005.de

|||Jens ... How can tell this? What service should I examine? I don't see any reference to the Sql Native client, other than I know it's installed.

I thought this process consisted of:

- install the Sql Native Client on target machine
- put a local copy of the database on target machine
- connect to the mdf with a local user instance

As I said, I can connect to remote server database from the machine. The folder names differ from my development machine to the target machine, but that shouldn't make difference, should it? I will say that in Sql Express Manager on my dev machine (which works), the full path and database name (i.e..c:\_source\project\mydata.mdf) shows in the database tree.

Rick|||

Hi Rick,

SQL Express does not allow attaching database from a UNC or mapped drive. It wasn't totally clear, but it reads like that what you're trying to do. Also, you can not connect to a User Instance on a different machine as User Instances only support local named pipes connections.

Mike

|||Nevermind. I'm apparently having a mental episode and forgot the one vital requirement of installing SqlExpress on the target instead of just the Sql Native Client. Hadn't had to do this in a while since I've been hitting a server for Sql Express databases. Sorry!

Rick

can't connect to local user instance

Just when I think I have this stuff figured out, it bites me back everytime.

I'm

trying to deploy an mdf out to a different machine, and attached to it with local user instance. I connect without problem from my development

machine with a local user instance, which also has Express Manager resident,

and I can connect to a server instance without problem.

What I can't do is

copy the .mdf database over to another workstation, which has Sql Native

Client installed, and connect to the database using a local user

instance! I can connect to a server instance without problem from this

other workstation. Here's my connect string for local user instance

that works fine from my dev machine:

Provider=SQLNCLI.1;Persist

Security Info=False;Integrated Security=SSPI;Data

Source=.\sqlexpress;AttachDBFileName=<full path_name and mdf

filename>;User Instance=true;

The error I get upon trying to connect with other stations is:

Error -2147467259
Database not found or cound not connect to database

I've

tried this every way I know how. I've copied the database from my dev

machine both with and without having detached the database from the

local instance. I've tried detaching from a server instance and copying

the file over. Nothing works, and I've done this before! What gives with this thing?

Rick

Hi,

is SQL Server Service allowed to access the datafiles ?

Jens K. Suessmeyer.


http://www.sqlserver2005.de

|||Jens ... How can tell this? What service should I examine? I don't see any reference to the Sql Native client, other than I know it's installed.

I thought this process consisted of:

- install the Sql Native Client on target machine
- put a local copy of the database on target machine
- connect to the mdf with a local user instance

As I said, I can connect to remote server database from the machine. The folder names differ from my development machine to the target machine, but that shouldn't make difference, should it? I will say that in Sql Express Manager on my dev machine (which works), the full path and database name (i.e..c:\_source\project\mydata.mdf) shows in the database tree.

Rick|||

Hi Rick,

SQL Express does not allow attaching database from a UNC or mapped drive. It wasn't totally clear, but it reads like that what you're trying to do. Also, you can not connect to a User Instance on a different machine as User Instances only support local named pipes connections.

Mike

|||Nevermind. I'm apparently having a mental episode and forgot the one vital requirement of installing SqlExpress on the target instead of just the Sql Native Client. Hadn't had to do this in a while since I've been hitting a server for Sql Express databases. Sorry!

Rick