Showing posts with label asp. Show all posts
Showing posts with label asp. Show all posts

Wednesday, March 28, 2012

Moving a logic loop to SQL Server

I am using C# and ASP.NET 2.0, with SQL Server 2000. In my database I have a table that is similar to the following:

WebpageId WebpageAddress Handler
1 /company/about ~/about.aspx
2 /blog ~/blog.aspx

As you can guess, one of my queries will be a SELECT command where WebpageAddress = @.address.

The hiccup I have is with a friendly URL such as the following:

/blog/2005/10/6

The friendly URLs have no extension, so I cannot immediately "pick out" the extension. (If the address were /blog.aspx/2005/10/6, then things would be simpler.)

What I am doing at present is using a loop in C# where I first perform a query with that full address. If no match is found, I trim the address back to the last slash (/blog/2005/10) and perform another query. If no match is found, I trim the address (/blog/2005) and perform another query. Again, no match is found, so I trim the address again (/blog) and perform yet another query. This time, a match is found, in which case the URL rewriting looks vaguely like this:

~/blog.aspx?parameters=2005/10/6

While this works fine, these friendly URLs require hitting the database up to four or five times. My question is, can this looping logic be moved to SQL Server?

My SQL knowledge is extremely basic, so I am just looking for someone to point me in the right direction. If it is not possible, I'd love to know now rather than wasting hours trying. If it is possible, I've love to know the keyword or technique involved, so that I can Google for the full answer.

SELECT TOP 1 Handler
FROM MyTable
WHERE WebpageAddress=SUBSTRING(@.address,1,LEN(WebpageAddress))
ORDER BY LEN(WebpageAddress) DESC

I think will give you what you want. However, to answer your question, yes, you can loop as well, but it'd be slower.

Friday, March 23, 2012

Moved asp.net app to network share, cant access SQL

I've recently moved an asp.net website from my PC to a network share because another tech it going to be working on it. I finally got the correct permissions on the network share and the correct .NET Framework settings on my PC to be able to run the app. Now I can't access the SQL server which is on a different server. Getting the following error:

Request for the permission of type 'System.Data.SqlClient.SqlClientPermission, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

How to I setup access to my SQL server for the app from any given PC on my LAN?

Your current error is not SQL Server permissions but CAS(code access security) you have to fix that before, you can get the error related to SQL Server permissions if any. The two links below covers the issues related to your error. Hope this helps.

http://forums.asp.net/thread/1522588.aspx

http://blogs.msdn.com/shawnfa/archive/2003/06/20/57023.aspx

Monday, February 20, 2012

Move databas from express to sql 2000

Hi!

I have created i webpage whos has a logged in system which is cretead in VS 2005 with the function ASP.NET configuration.

And know will i move all databas to i a MSSQL 2000 there i only can have one databas, And know i have ASP.NET logged in Databas and one site databas.

I just wondering if its possible to make i virtual connection with MSSQL 2000? If not somebody has some idés for me?

I hope you can understand me.

If I understand, right now on your development environment you have the ASPNETDB database (logged in system) and also a site database. And you need to move to SQL Server 2000 where you'll only have one database.

You can combine the security schema (aspnetdb) and the site schema into the same SQL 2000 database - this should not be a problem. To install the ASP.Net security schema into an existing SQL 2000 database, you can run aspnet_regsql.exe against the database. So if the site database is already on this SQL 2000, just run aspnet_regsql against the same database (or get the DBA to do so) and then you'll need to point your database connection (in the web.config) against the SQL Server.

|||

Ok, tanks!

But i don't know how i do that. can you explain? If you want step by step.

The sql server and the webserver is on a webhotel, so i can't do any configuration.

|||

someone who can explain for me?

Now i just have to move the login database (ASTNETDB) into another database (a SQL 2000 database)

Someone?

|||

So now i know how i have to do. But when i use the aspnet_regsql.exe so i get a error.

Error

Grantor does not have GRANT permission.

The error comes when installCommon.sql