Friday, October 7, 2011

Default value and constrain of a table

So I add a new column to an existing table, and I create it using a command like this:
ALTER TABLE table_name
ADD TagUploader bit not null default 0;

but I then I change my mind, the datatype should be tinyint instead of bit, so I try to alter the table again using this line:
ALTER TABLE table_name
ALTER COLUMN TagUploader tinyint;

but this error message was shown in the message frame:


Msg 5074, Level 16, State 1, Line 1
The object 'DF__PROFILE__tagUplo__6CA31EA0' is dependent on column 'TagUploader'.
Msg 4922, Level 16, State 9, Line 1

ALTER TABLE ALTER COLUMN TagUploader failed because one or more objects access this column.

then I tried to drop the column, still appear a message like this:

Msg 5074, Level 16, State 1, Line 1
The object 'DF__PROFILE__tagUplo__6CA31EA0' is dependent on column 'TagUploader'.
Msg 4922, Level 16, State 9, Line 1
ALTER TABLE DROP COLUMN TagUploader failed because one or more objects access this column.

So the problem is that I create a default value at the creation of that column, that creates a constrain to the table, you can find it in the Constrains folder inside the table's tree
have tried to delete it by right clicking it, then choose delete but an error like this appears:

So I guess the major problem is the constrain, so I search a way to drop the constrain, and yes there is a way, the line was like this:

ALTER TABLE docsadm.profile
DROP CONSTRAINT [DF__PROFILE__tagUplo__6CA31EA0]
GO

After running that script, it will show this message:
Command(s) completed successfully.

Then after that, you can alter the column or even drop the column without any problem anymore. So what I learned from this case is that default value can create a constrain to the table, if you don't need it, just release it.

-thats all folks, says bugs bunny :P-




Tuesday, October 4, 2011

share folder files to be access from asp.net application

So I have a PDF Web Viewer application, its located on server, an usually, the document is put on the same server, so the full path should be like this: C:\folder name\doc folder
and the document can be viewed from client.

Last time I deployed the application to production, they (my customer) said that the file server is on different server, so it will be a share folder, the path is gonna be like this: \\server_name\sharefolder$

Then after I re-setting the application's config into new document folder path, and it result on the my application have access denied. And the condition is, the share folder cannot be granted to everyone, so I set only for Domain\Administrator.

After testing several times, giving the security of the folder to ASPNET user, NETWORK SERVICE user, still doesn't working.

In my desperation, I set Sharing permission to Everyone, and yes it works, but that 's not gonna solve the security issue. Then I tried to set Everyone to Security (not Sharing) and remove the one on Sharing tab, still not work. Then I think, there should be somebody that has to be added on Sharing so it will work, not on Security.
Try to add ASPNET user, but still not working. Then my last chance, NETWORK SERVICE, and tadaaaa.. it works like a charm.

So what I want to say here is, I think we cannot assume that Security is more powerful that Sharing tab. The two of it has it's own behaviour, in this case, the NETWORK SERVICE user has to be added in Sharing tab, not Security. But added in both tab will also works :D

thats all, hope it helps.






update:
Oh yeah, i forgot, there is something you have to set in IIS, gave to the one which have access to that folder. to get to this window, right click on your website, then choose properties.

Saturday, October 1, 2011

error page not found asp.net

so after you have deploy your application to IIS and already set the ASP.NET to the right version, but after you try to browse it, it display Page Not Found.

The problem is... maybe you haven't allowed the .net framework. You have to set the .Net Framework in Web Service Extensions to Allowed instead of Prohibited. That's all.. :)

PS: the Web Service Extensions folder is located in IIS 6, on the bottom of the treeview on left frame.

error when backing up database

this error happens when I was trying to backup SQL Database using scripts:

error Cannot open backup device 'F:\foldername'. Operating system error 5(Access is denied.)

the solutions is:
.
.
.
assign a more powerful user to SQL Server Service

source:
http://social.msdn.microsoft.com/forums/en-US/sqldatabaseengine/thread/021c7aa5-4a8a-4bbb-8ff0-fe6b03920aae/