Thursday, February 14, 2008

Enabling Diagram support (database schema creation) in SQL Server 2005

Diagram support for attached or backed up databases.

The solution has been put on this blog a while ago (nice post). I have tried searching before, yet, a few days ago, I search with one of my collegues, and found that this blog is very helpful on that. The reason for this post, is just to add another link on google, that gives somewhat a confirmed solution on this issue.

http://geekswithblogs.net/timh/archive/2006/07/05/84171.aspx

I tried what was suggested in the above blog, did not work for me at first (it worked for others). but what did work for me is the following reply on that same post :

Begining quote from the post above

# re: Cannot add diagram to SQL Server 2005 DB: Database diagram support objects cannot be installed because this database does not have a valid owner. 8/16/2006 9:39 AM Julius

I tried the above mentioned solution but still was not working and displaying the same error message - if you got the same error as me then just try the follwing lines in SQL Query:

EXEC sp_dbcmptlevel 'dbname', '90'; 
ALTER AUTHORIZATION ON DATABASE::dbname TO valid_login



 



End Quote From the blog post above



Comments are welcome

Thursday, February 07, 2008

asp.net 2.0 Roles DropDownList Control in C#

Translation of this post to french at :
http://s4n44.blogspot.com/2008/02/aspnet-20-dropdownlist-de-rles-enc.html

This is a user control, which encapsulates a DropDownList, an ObjectDataSource and custom, simplified roles class. The user control will connect automatically (of course), with the aspnetdb database pointed to in the web.config
for vb.net users, here's a nice converter provided by Telerik (http://www.telerik.com ) :
http://www.codechanger.com/

Here's the code for the user control :

<%@ Control Language="C#" AutoEventWireup="true" CodeFile=" ddlRoles.ascx.cs" Inherits="RoleControl" %>
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="sourceRoles" DataTextField="RoleName"
DataValueField="RoleName" Width="185px">
</asp:DropDownList>
<asp:ObjectDataSource ID="sourceRoles" runat="server" SelectMethod="GetRoles"
TypeName="CustomRoles"></asp:ObjectDataSource>


Code behind for the user control:


using System;

public partial class RoleControl : System.Web.UI.UserControl
{
public String SelectedValue
{
get { return this.DropDownList1.SelectedValue; }
set { this.DropDownList1.SelectedValue = value; }
}
}


The object datasource uses the class below :


using System;
using System.Web.Security;
using System.Collections.Generic;

public class CustomRoles
{
private string mRoleName;

public string RoleName
{
get { return mRoleName; }
set { mRoleName = value; }
}

/// <summary>
/// this function, loops through all roles in the database, and builds
/// a collection of CustomRoles instances into a generic list of CustomRoles
/// then we return the list as the source for the dropdown.
/// The RoleName property is used to bind the datavaluefield and datatextfield
/// in the dropdownlist
/// </summary>
/// <returns></returns>
public List<CustomRoles> GetRoles()
{
//getroles
string[] roleslist = Roles.GetAllRoles();

int i = 0;
//instance of customroles
CustomRoles br;

//create the list (or collection of CustomRoles instances)
List<CustomRoles> lstbr = new List<CustomRoles>();

//fill the list by looping through the array of strings
foreach (string brole in roleslist)
{
br = new CustomRoles();
br.RoleName = brole;
lstbr.Add(br);
}

return lstbr;

}

}


Comments are welcome !