Pages

Sunday, March 30, 2008

printers connected to your computer

This code sample gets you the list of all connected printers (both local and network printers).

Microsoft.Win32.RegistryKey rk;
rk = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"Printers\Settings");
string[] printernames = rk.GetValueNames();
if (printernames.Length > 0)
{
foreach (string s in printernames)
{
{
Console.WriteLine(s);
}
}
}

Convert Database data to XML

The data existing in the relational database can be easily converted into an xml documant in the program. The following code illustrates this.

I have used SQLServer database table employee ( with columns empid, first_name,last_name,deptcd,salary and resig_status) The connection is established using appropriate connection string. The data from the RDBMS table is stored in the dataset dsEmp. The xml class XmlDataDocument is used to convert the data into an xml data file. It takes the dataset as input and converts to xml data.

{
DataSet dsEmp = new DataSet();
string strCon;
string strSelect;

strCon = "data source=SQLEXPRESS;initial catalog=dbemp;persist security info" +
"=False;user id=sa;password=jadoogar;workstation id=HCL;packet size =4096";
strSelect = "Select empid,first_name,deptcd from employee";

try
{
SqlConnection sqlCon = new SqlConnection(strCon);
SqlDataAdapter empAdapter = new SqlDataAdapter(strSelect,sqlCon);
empAdapter.Fill(dsEmp,"employee");
}
catch
{
}
XmlDataDocument empDoc = new XmlDataDocument(dsEmp);
empDoc.Save(MapPath("xmldata/newemp.xml"));

}

Saturday, March 15, 2008

Data Modeling

data modeling is the process of creating a data model by applying a data model theory to create a data model instance. A data model theory is a formal data model description. See database model for a list of current data model theories.

When data modeling, we are structuring and organizing data. These data structures are then typically implemented in a database management system. In addition to defining and organizing the data, data modeling will impose (implicitly or explicitly) constraints or limitations on the data placed within the structure.

Managing large quantities of structured and unstructured data is a primary function of information systems. Data models describe structured data for storage in data management systems such as relational databases. They typically do not describe unstructured data, such as word processing documents, email messages, pictures, digital audio, and video.

A data model instance may be one of three kinds (according to ANSI in 1975[1]):

--> a conceptual schema (data model) describes the semantics of a domain, being the scope of the model. For example, it may be a model of the interest area of an organization or industry. This consists of entity classes (representing kinds of things of significance in the domain) and relationships (assertions about associations between pairs of entity classes). A conceptual schema specifies the kinds of facts or propositions that can be expressed using the model. In that sense, it defines the allowed expressions in an artificial 'language' with a scope that is limited by the scope of the model. For generally applicable models, see below under 'Generic data model'.
--> a logical schema (data model) describes the semantics, as represented by a particular data manipulation technology. This consists of descriptions of tables and columns, object oriented classes, and XML tags, among other things.
--> a physical schema (data model) describes the physical means by which data are stored. This is concerned with partitions, CPUs, tablespaces, and the like.

Debug a T-SQL Stored Procedure

1) In a new SQL Server project, establish a connection to the AdventureWorks sample database.

2) Create a new stored procedure using the code from the first example section below, and name it HelloWorld.


CREATE PROCEDURE HelloWorld
AS
DECLARE @mynvarchar NVARCHAR(50),
@myfloat FLOAT
SET @mynvarchar = @@VERSION
SET @mynvarchar = 'Hello, world!'
SET @myfloat = 1.6180
PRINT @mynvarchar
RETURN (0)

3) Set breakpoints in HelloWorld, and step into the stored procedure. The instruction pointer, designated by a yellow arrow, will appear on the line SET @mynvarchar = @@VERSION, the first executable line of code in the stored procedure.

4) Try out different debugging features.

4.1) Make the Locals window visible. To do so, on the Debug menu, click Windows, and then click Locals. Notice that the parameters and local variables are displayed in the Locals window with their corresponding values. You can edit the values of the variables in the Locals window as the stored procedure runs.

4.2) Press F10 to step one line in the stored procedure. Notice that the value of the variable @mynvarchar has changed in the Locals window and its value is now displayed in red, indicating it has changed.

4.3) Make the Watch window visible. To do so, on the Debug menu, click Windows, and then choose Watch.

4.4) In the Text Editor, double-click the @mynvarchar variable to select it. Drag @mynvarchar to any location on the Watch window. The variable is now added to the list of watched variables.

4.5) In the Text Editor, right-click the line Return (0), and on the shortcut menu, click Insert Breakpoint.

4.6) On the Debug menu, click Continue.

5) Choose Continue again to finish debugging the stored procedure.

Enable CLR Debugging

1) Open Server Explorer.

2) In Server Explorer, right-click on the connection you want to debug and choose Allow SQL CLR Debugging. This setting enables SQL CLR debugging for all connections on the server.

3) A message box appears with the warning: "SQL CLR debugging will cause all managed threads on the server to stop. Do you want to continue?". When you are debugging SQL CLR database objects, breaking execution will break all threads on the server, affecting other users. For this reason, you should not debug SQL CLR applications on a production server.

4) Click Yes to enable debugging.

Sunday, March 9, 2008

undocumented extended stored procedures

An extended stored procedure (xp) is a dynamic link library that runs directly in the address space of SQL Server and is programmed using the SQL Server Open Data Services API. You can run extended stored procedures from the Query Analyzer, for example, just as you would normal stored procedures. Extended stored procedures are used to extend the capabilities of SQL Server. You can take advantage of the many extended stored procedures that come with SQL Server, or you can write your own in a programming language such as C or C++.

sp_MSgetversion
This extended stored procedure can be used to get the current version of Microsoft SQL Server. To get the current SQL Server version, run

EXEC master..sp_MSgetversion

Note. A more common way to retrieve the current SQL Server version (this way provides more information) is to use following SELECT statement:

SELECT @@version

xp_dirtree
This extended stored procedure can be used to get a list of all the folders for the folder named in the xp. To get a list of all the folders in the C:\MSSQL7 folder, run:

EXEC master..xp_dirtree 'C:\MSSQL7'


xp_enum_oledb_providers
This extended stored procedure is used to list of all the available OLE DB providers. It returns Provider Name, Parse Name and Provider Description. To get a list of all OLE DB providers for your SQL Server, run:

EXEC master..xp_enum_oledb_providers


xp_enumcodepages
This extended stored procedure can be used to list of all code pages, character sets and their description for your SQL Server. To get a list of all code pages and character sets, run:

EXEC master..xp_enumcodepages


keep watching for more information