Friday, March 25, 2011

Repair a SQL Server 2008 Suspect database after upgrading

Lately, I've installed SQL Server 2008 Developer Edition in my pc and migrated all sql server 2005 databases.

Upon attaching/restoring all databases, some were marked as suspect. Below is the sql script to repair those databases.
1:  EXEC sp_resetstatus 'Test';  
2:    ALTER DATABASE Test SET EMERGENCY  
3:    DBCC checkdb('Test')  
4:    ALTER DATABASE Test SET SINGLE_USER WITH ROLLBACK IMMEDIATE  
5:    DBCC CheckDB ('Test', REPAIR_ALLOW_DATA_LOSS)  
6:    ALTER DATABASE Test SET MULTI_USER  

But as a precautionary measure,I have back-up plans for each database,as to have another copy when things go wrong.

Test is the database name.

Source: how-to-repair-sql-server-2008-suspect

Saturday, March 19, 2011

Deploying asp.net websites using ASP.NET Membership Framework

In my case, i have been experimenting an e-commerce application which uses asp.net membership framework. If I run the website using visual studio 2008, it successfully logs in using the users i have created using the built-in asp.net website administration tool.

However, if you deploy this on a production server such as IIS, you cant' log-in. The solution is straightforward in this link:
Configuring ASP.NET 2.0 Membership

Friday, March 18, 2011

Clear Sessions after logout button is clicked

Solution I found is on this link: ASP.NET Forum Link

Wednesday, March 16, 2011

Install IIS on Windows 7 Home Premium

Here's the link: Technet Link

Thursday, March 10, 2011

Unable to Open EDMX (Entity Framework in Design View) After Closing

Scenario: You may have recently added an entity framework that maps to an sql server table. After that, you suddenly close it. But when you tried to double click the Entity model, it does not open in the design view.
Solution: Cannot Open .edmx file in the designer

Wednesday, March 2, 2011

Insert Parameter Array in .NET (C# Version)

The first version i created was a vb.net version. Here is the C# version:
Code:
  myConn objCon = Program.connectionstring;  
        string str = objCon(); //pass delegate to string  
        SqlConnection connection = new SqlConnection(str);  
        try  
        {    
          List<Patient>patients = new List<Patient>();  
          for(int i = 0; i < 5; i++)  
          {  
            Patient patient = new Patient();  
            patient.name = "greg" + i;  
            patient.code = i*2;  
            patients.Add(patient);  
          }  
          //insert into array  
          connection.Open();  
          StringBuilder query = new StringBuilder();  
          SqlCommand cmd = new SqlCommand();  
          for (int j = 0; j < patients.Count; j++)  
          {  
            query.Append(string.Format("Insert into patients  
              (PatientName,PatientSexCode)  
              values (@names{0},@code{1});",j,j));  
            //declare the parameters  
            cmd.Parameters.AddWithValue(String.Format  
              ("@names{0}",j), patients[j].name);  
            cmd.Parameters.AddWithValue(String.Format  
              ("@code{0}",j), patients[j].code);  
          }  
          cmd.Connection = connection;  
          cmd.CommandText = query.ToString();  
          cmd.ExecuteNonQuery();  
        }  
        catch (Exception exception)  
        {  
          throw new Exception(exception.Message);  
        }  
        connection.Close();  
        Console.Write("Array successfully saved");  
        Console.ReadLine();  

Tuesday, March 1, 2011

Change Default Browser ASP.NET MVC

To change a default browser for an asp.net mvc website to render is not straightforward. However, the steps are just easy:
1. Add a webform or a static html to the application, just leave the default name.
2. Right click on the newly added webform.
3. Click Browse With.
4. Choose the browser like Firefox, IE, or Chrome.
5. Mark it as default.

Thats it!!!