Tuesday, November 22, 2011

Delete All Tables MSSQL

While working on ASP.Net application, I came across a situation where I had to delete all the Tables of the MSSQL 2008 database, and it was really painful process. 

In this case I had to delete all the SPs and all views as well. As I started searching like "Truncate database Sql 2008" or "Delete all tables in MSSQL" I came across two things and it worked for me.

(I am really not sure whether it works in all the cases but for Deleting all tables in SQL, this worked for me.) 
Firstly we need to remove all indexs from SQL table, I found following code when I Google the term 


DECLARE @indexName NVARCHAR(128)
DECLARE @dropIndexSql NVARCHAR(4000)

DECLARE tableIndexes CURSOR FOR
SELECT name FROM sysindexes
WHERE id = OBJECT_ID(N'tableName') AND
  indid > 0 AND indid < 255 AND
  INDEXPROPERTY(id, name, 'IsStatistics') = 0
ORDER BY indid DESC

OPEN tableIndexes
FETCH NEXT FROM tableIndexes INTO @indexName
WHILE @@fetch_status = 0
BEGIN
  SET @dropIndexSql = N'DROP INDEX tableName.' + @indexName
  EXEC sp_executesql @dropIndexSql

  FETCH NEXT FROM tableIndexes INTO @indexName
END

CLOSE tableIndexes
DEALLOCATE tableIndexes

After this we need to delete all the tables in SQL, for this I used following SP
EXEC sp_MSforeachtable @command1 = "DROP TABLE ?"

It seems that this is a HIDDEN stored procedure in MSSQL.
Submit this story to DotNetKicks

Read more...

Sunday, November 20, 2011

Access userName asp.net-membership without using Membership.getUser()

While I was working on Membership and User Management in Asp.Net 2010
Following Scenario
  • After creating user, admin sets subscribtion for the user.
  • User logs in with id and password, after validating user, I check for subscription details.
  • If user is logging in with subscription period he/she has access to the application else he/she will be redirected to Subscription Expired page.
To check subscription, I had requirement to get username and check it in Subscription table.
I did not want to use getUser function, as I just wanted to get user name of currently logged in user.

To get user name I used following line of code

System.Web.HttpContext.Current.User.Identity.Name


Submit this story to DotNetKicks

Read more...

Friday, November 18, 2011

Error : Could not find any resources appropriate for the specified culture or the neutral culture

Just recieved this error:
Could not find any resources appropriate for the specified culture or the neutral culture.  Make sure "AjaxControlToolkit.Properties.Resources.NET4.resources" was correctly embedded or linked into assembly "AjaxControlToolkit" at compile time, or that all the satellite assemblies required are loadable and fully signed. 

Could not find any resources appropriate for the specified culture or 
the neutral culture.  Make sure 
"AjaxControlToolkit.Properties.Resources.NET4.resources" 
was correctly embedded or linked into assembly "AjaxControlToolkit" 
at compile time, or that all the satellite assemblies required are
loadable and fully signed.

Ajax Tool kit realted .Net errors look a lot more worse than they really are.
What we have to do is simply add scriptManager ;)
 
<ajax:ToolkitScriptManager 
ID="ToolkitScriptManager1" 
runat="server" />
Submit this story to DotNetKicks

Read more...