This blog is specially designed for the programmars related to .NET Technology as I am too. Here one can find the solution of his/her problem related to C#,ASP.NET, SQL Server 2000.
ERROR:Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
Cause: This error occurs when a database query or stored procedure is not able to complete execution before a pre-set timeout period expires.
Solution: Dim com AsNew SqlCommand(sql, myConnection, myTrans) com.CommandType = CommandType.Text
com.CommandTimeout = 0
Note: CommandTimeout property is documented to support a value of 0, which provides for an infinite timeout. The default is 30 seconds. But sometime setting timeout value to zero, creates a problem, therefore it will be better to set timeout property to the maximum i.e. 7200.
When we insert data in datetime type variable in sql server, sometimes we face error like below:
The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
This is all due to the date time FORMAT problem. SQL accepts mm/dd/yyyy format (by default setting, however we can change it, but it is out of topic), while we often provide dd/mm/yyyy format.
So we have two option, either we should provide the correct format from front end, or we need to apply any trick on back end (on sql server end).
Here we goes with both type of solution...
At first from Front End (here I am using VB.NET)
Dim [date] AsString = "29/03/2010" 'format is MM/dd/yyyy
Dim dateTimeFormatterProvider As System.Globalization.DateTimeFormatInfo = TryCast(System.Globalization.DateTimeFormatInfo.CurrentInfo.Clone(), System.Globalization.DateTimeFormatInfo)
Dim dateTime As DateTime = dateTime.Parse([date], dateTimeFormatterProvider)
Dim formatted AsString = dateTime.ToString("MM/dd/yyyy")
OUTPUT : 3/27/2010
Now at Back End i.e. SQL SERVER
SELECTCASE WHEN ISDATE('27/03/2008')= 0 THENCONVERT(DATETIME,'27/03/2010',103)ELSE'27/03/2010'END
Expanation:
ISDATE('27/03/2008') function takes single arguments of text type and returns 1 if the supplied argument is valid date or return 0 if the supplied argument is invalid date.
CONVERT(DATETIME,'27/03/2010',103) function takes 3 arguments, first dattype in which we need to convert the datetime, second datetime in text format and last one is format (viz. 100,101,103,105 etc), in which conversion is possible.
Here is the complete details of these possible codes: SELECTCONVERT(CHAR(19),CURRENT_TIMESTAMP, 0)
Sometimes we need to write or format sql (SQL Server 2000, 2005, 2008) int 1 as varchar or string '01' or '001'.
Or there may be the case when the number stored in column is a single digit and we need to convert it into a 2 or 3 (Two or Three) digit string that begins with a 0 (Zero).
Simply say Displaying 2 or 3 digit number left padding with 0 (Zero).
e.g 1 as '01', 2 as '02' and 17 as '17'
or 1 as '001' 2 as '00' and 175 as '175'
etc.
OK, No Problem Try Following Logic..
For 2 Digit Padding or Formatting
RIGHT('00' + LTRIM(STR(<YourNumber>)),2)
In Case of Select Statement
SELCT RIGHT('00' + LTRIM(STR(<YourNumber>)),2)FROM tableName
For 3 Digit Padding or Formatting
RIGHT('00' + LTRIM(STR(<YourNumber>)),2)
In Case of Select Statement
SELCT RIGHT('000' + LTRIM(STR(<YourNumber>)),3)FROM tableName
Sometimes, We want to DROP a USER of DATABASE but an ERROR occurred: 'The database principal owns a schema in the database, and cannot be dropped.'
This happens as when we create user and assign its role to db_owner or something else, it makes an entry in the schema of db_owner or other roles.
So, if we want to delete the user, we need to make the same changes to all the schemas where the "Database Principal" is having/owning the role. For Example, if it is having "db_owner, db_datareader, db_datawriter" roles; then we have to make the above said changes for all these 3 schemas.
Let's assume, we want to delete an user 'user1' assigned role 'db_owner' and 'db_datareader'. For it, our_DB_Name > Schemas > db_owner > right click > select properties Here we would find the name of 'user1', We would change it to any other like 'dbo'. Do the same for 'db_datareader' i.e. our_DB_Name > Schemas > db_datareader> right click > select properties Here we would find the name of 'user1', We would change it to any other like 'dbo'.
That's All. Now, We can easily delete the 'user1'.
Sometime you may come across a situation when you want to disable CUT, COPY or PASTE from/in any TextBox in ASP.NET. e.g. Whenever you want to force user to type CONFIRM PASSWORD not by simply copy paste, but via TYPING IT IN TEXT BOX, then you may need this code.
Nothing to do.. just add few small script in .aspx file as bellow
Whenever you want to execute any webservices from any other machine than local machine, on which the webservices are created, you get an error message like bellow
"The test form is only available for requests from the local machine"
If you simply open the web config file and add the following, you will be able to access the test form outside of the localhost.
You need to write this code segment inside "SYSTEM.WEB" tag which is inside "CONFIGURATION" tag...