Drunkard's Walk Forums

Full Version: Okay, brain-picking time.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm cramming for the coding test part of my second interview with the local company.  The fellow knows I'm lacking in SQL Server, and he's told me he's looking for more than just coding skill for his hire, but I want to ace this.  The actual test as described is pretty simple, even for someone like me who hasn't worked in SQL Server before.  But I've been having one persistent problem, and I can't figure out what I'm doing wrong.  I'm hoping someone here with SQL Server experience can tell me what it is, and how to correct it.
Setup is this:  I've using Microsoft SQL Server Management Studio 2008 Express Edition to set up a stored procedure for a little table -- a simulated customer base with 10 records -- that I created to run a query against.  Simple procedure, runs this query with the appropriate parameters:
    SELECT firstname, lastname, customernumber, customersince
    from dbo.dummydatabase
    where customersince between @customerstart and @customerend;
"customersince" is a datetime field, and customerstart/customerend are datetime params.  I created the stored procedure with the context menu "New Stored Procedure" option.  The little table lives in master and as you can see from the query is called "dbo.dummydatabase".  The stored procedure is in master's Stored Procedures under Programmability, and itself is called "dbo.customer_age". 
The problem is that when I try to run it from an ASP.NET page I've set up in Visual Web Developer 2008 Express Edition, I get a "procedure not found" error.  I also get the same error inside SQL Server Management Studio from the dynamic syntax-checking system, but I can still run the procedure via a separate query despite this.  Obviously I did something wrong, but damned if I know what.  Can anyone help?
Thank you.
(Edit:  Corrected vague/incomplete terminology.)
-- Bob
---------
Then the horns kicked in...
...and my shoes began to squeak.

The Wanderer

I don't have experience with SQL Server, but I did find something potentially relevant with a bit of Google-fu; feel free to ignore it if it's something you already know.

According to a quick Google search (on 'SQL Server ASP "procedure not found"'), two possible causes for this are the connection string being incorrect (i.e. it's not actually connecting to the database properly) and the rights on the server not being correct (i.e. the thing doing the connecting can't access the context where the procedure would be found).

I would expect that there might be something more useful in the SQL Server 2008 documentation, available for apparently free download from Microsoft, but that requires .NET and various hoop-jumping which means it's inaccessible to me since I run Linux.

I hope that's helpful, unlikely though the possibility may be...
Thanks, I'll look into those in the morning, when I'm a bit more awake.
-- Bob
---------
Then the horns kicked in...
...and my shoes began to squeak.
Update: I took a quick look after reading that, and discovered that I somehow had two servers running at once, and I had the ASP.NET page's server object pointed at the wrong one. I fixed that, but I'm still getting the "can't find stored procedure" error. I'll jump back on it in the morning when I'm somewhat more rested. Again, thanks.
-- Bob
---------
Then the horns kicked in...
...and my shoes began to squeak.
Further update: I got it to work. I hadn't properly configured the SQLDataSource object to look at the right server and use the stored procedure.

My god, I think I might get through this thing.
-- Bob
---------
Then the horns kicked in...
...and my shoes began to squeak.
Just as a quick note, though it's likely not going to come up in the test:
Storing tables, stored procedures (sprocs), views, and so on in 'master' is generally considered incorrect.  You want to create a database that you then store these things in.  'master' is where all the important bits that drive SQL Server live, and stepping on them -- as you all too easily can with sa access -- is, uh, bad form, to say the least.
User functions are permissible in master, generally, but it's still better to slap them into their own database too.
Basically, it's like storing all your documents in, say, c:windowssystem32 (for a Windows box).  Can you?  Sure.  Will it break anything?  Probably not.  Does it increase your risk of ham-fingering something and blowing stuff up?  Hell yes.

--sofaspud
--"Listening to your kid is the audio equivalent of a Salvador Dali painting, Spud." --OpMegs
Thanks for the advice. I was just using the defaults while learning how to make the stuff work in the first place -- now that I have, I can refine it a little.
-- Bob
---------
Then the horns kicked in...
...and my shoes began to squeak.