Sunday, November 13, 2016

MongoDB cannot start server:I CONTROL [initandlisten] dbexit: rc: 100

Step1: Open Command Prompt--> Run as Administrator

Step2: Write the command as follows in your Mongo/bin directory:

For Example:-

c:\bin\mongod --storageEngine=mmapv1 --dbpath c:\data

Should solve the problem.

Thursday, October 2, 2014

Query to store image in sql server database

What about BLOB?

SQL Server stores standard INT, CHAR, and VARCHAR data directly within a row. However, this approach limits the maximum capacity of each data type to 8000 bytes, slightly less than SQL Server’s maximum row size of 8060 bytes.
Although more than adequate for most data types, the 8KB limit is a problem for most BLOB data. To accommodate the needs of larger BLOB data, Microsoft designed SQL Server to handle BLOB storage differently than it handles storage for more common data types. Figure 1 shows an overview of how SQL Server 2005 and earlier releases store the IMAGE and VARBINARY(MAX) BLOB data types.
Figure 1: Overview of SQL Server's BLOB storage architecture
As you can see in Figure 1, SQL Server doesn’t store large BLOB data on the same data page as the data for the rest of the row. Instead, it stores BLOB data as a collection of 8KB pages organized in a B-tree structure. Each row’s BLOB column contains a 16-byte pointer to the root B-tree structure, which tracks the blocks of data that comprise the BLOB. If the data is less than 64 bytes, SQL Server stores it as part of the root structure. Otherwise, the root structure contains a series of pointers to the data blocks that comprise the binary object.
For BLOBs smaller than SQL Server’s 8KB page size, you have a couple of options for storing the BLOB data inline, as you would standard text and numeric data. For the old TEXT, NTEXT, and IMAGE data types, which SQL Server 2005 continues to support, you can use the text-in-row feature to store the data inline. And for the new VARCHAR(MAX), NVARCHAR(MAX), and VARBINARY(MAX) data types, you can use the backward-sounding large value types out of row option. Storing smaller BLOB data inline improves performance, avoiding the extra I/O needed to read the BLOB data record. 
Example
CREATE TABLE Images(image varbinary(max))
INSERT INTO Images(image)
SELECT * FROM
OPENROWSET(BULK N'C:\Image1.jpg', SINGLE_BLOB)

Import multiple images to SQL Server using SSIS

Problem
Sometimes we need to import thousands of images to SQL Server. This example shows how to import a list of images to SQL Server using SQL Server Integration Services.
Solution

Requirements

  • SQL Server Enterprise or Standard (in this case I am using SQL Server 2008 R2, but it can work with SQL Server 2005 as well).
  • SSIS installed (it is included in the SQL Server installer).

Demonstration

  1. First of all, it is necessary to create a flat file named listImages.txt (or the name of your preference) with the paths of the images that you want to import to SQL Server such as the following:
    C:\images\pic1.jpg
    C:\images\pic2.jpg
    C:\images\pic3.jpg
  2. Create a table myImages with 3 columns: The ID is the primary key, image will store the picture and the path will store the image path:
     
    CREATE TABLE [dbo].[myImages](
     [id] [smallint] IDENTITY(1,1) NOT NULL,
     [path] [varchar](200) NULL,
     [image] [image] NULL,
     CONSTRAINT [PK_myImages] PRIMARY KEY CLUSTERED 
    (
     [id] ASC
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, 
    IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) 
    ON [PRIMARY]
    ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
    GO
  3. Start the SQL Server Business Intelligence Studio and create a New SQL Server Integration Project.
     
    The Business Intelligence Development Studio
  4. Drag and drop the Data Flow Task to the design pane.
     
    Drag and drop the Data flow
  5. In the design pane double click the Data Flow Task
  6. In the Data Flow tab drag and drop a Flat File Source, an Import Column and an OLE DB Destination.  Join the tasks with the green arrows as shown below.
     
    Create a Flat file, an import column and a OLEDB Destination
  7. The Flat File Source will connect to the listImages.txt created in step 1. Double click on the Flat File Source to edit the settings.
  8. In the Flat file connection manager, press New... 
    Select the flat file
  9. In the Flat File Connection Manager Editor write a Connection manager name (any name can be used. In this example we will use imagefile).
  10. In the File name press Browse... and select the listImages.txt file created in step 1 (it can be stored anywhere. In this example it is in c:\images\)
     
    Define the flat file delimiters
  11. Select the Advanced options and in the Name, type Path to change the column name as shown below.
     
    change column name
  12. Then click OK on each window to save these settings.
  13. Next double click the Import Column transform and click the Input Columns tab as shown below.
  14. In the Input Columns tab check Name
     
    Check the name
  15. Click the Input and Output Properties
  16. Open the Import Column Output tree and select the Output Columns as shown below.
  17. Click the Add Column...
  18. button and name the new column Image
     
    Select the output column
  19. Get the ID property value of the column created (in this example the ID is 42).
     
    Verify the ID
  20. In the Input and Output Properties tab, open the Import Column Input > Input Columns and select Path as shown below.
  21. In the FileDataColumnID property write the ID from step 18 (in this example 42) and press OK to save these settings.
     
    Specify the ID
  22. Double click the OLE DB Destination.
  23. In the OLE DB Destination Editor Window, press New... for the OLE DB connection manager.
     
    Select the OLE BD Destination
  24. In the Configure OLE DB Connection Manager, press the New... button.
     
    Create the Data Connection
  25. In the Connection Manager, in the Provider combo box, select Native OLE DB\SQL Server Native Client.
  26. In the Server name write the SQL Server Name (in this example, the local server name is used which can be specified with a period).
  27. Select the Log on to the server information (in this example Windows Authentication is used).
  28. In the select or enter the database name, select the database used to create the table in step 2 (in this example, the Adventureworks database is used) and press OK.
     
    Select the server name and Database
  29. In the OLE DB Destination Editor name of the table or the view, select the table created in step 2 (in this example the table name is myImages).
     
    Select the table
  30. In the OLE DB Destination Editor, press the Mappings page and then press OK.
     
    Map the columns
  31. Now we are ready to start the project. Press the start debugging icon (green arrow). If everything is OK, the tasks should be colored green and the number of rows imported should be displayed.
     
    Run the package
  32. To verify that the data was imported successfully, open SQL Server Management Studio.
  33. Go to the database (in this example, Adventureworks) and open the myImages table.
     
    Verify the values

Thursday, December 5, 2013

Use of XML File for Dynamically Storing Data and Retrieving Data in ASP.NET with C#

XML is really an interesting file that you can use as database in which you can store a set of data. Say for example, in your website project you want to have a page through which a user can enter his name, email ID and his comments. Such data may not be commercial for you to store in your data base but at the same time you want to have it for goodwill purposes. Here is the solution, store it in an XML file and retrieve its node values on a web page, it is as cool as that.

Using the Code

Here is an example to show how it can be done.

Step 1

Add a page within your solution with three text boxes to enter name (txtName), email(txtEmail) and comment (txtComment). Also place a button for submit (btnSubmit) as shown in the image below. You may add required field validators too.
1_small.JPG

Step 2

Add an XML file into your project solution and rename it (StoreUserInfo.xml). Create a root node into it:
<?xml version="1.0" encoding="utf-8"?>
<records>
</records>

Step 3

On button click, paste the following code:
protected void btnSubmit_Click(object sender, EventArgs e)
{
    XmlDocument oXmlDocument = new XmlDocument();

    oXmlDocument.Load(@"D:\Sanju\XMLDb1\StoreUserInfo.xml");
    XmlNode oXmlRootNode = oXmlDocument.SelectSingleNode("records");
    XmlNode oXmlRecordNode =     oXmlRootNode.AppendChild(
        oXmlDocument.CreateNode(XmlNodeType.Element,"record",""));
    oXmlRecordNode.AppendChild(oXmlDocument.CreateNode(XmlNodeType.Element,
        "Name", "")).InnerText = txtName.Text;
    oXmlRecordNode.AppendChild(oXmlDocument.CreateNode(XmlNodeType.Element,
        "Email", "")).InnerText = txtEmail.Text;
    oXmlRecordNode.AppendChild(oXmlDocument.CreateNode(XmlNodeType.Element,
         "Comment", "")).InnerText = txtComment.Text;

    oXmlDocument.Save(@"D:\Sanju\XMLDb1\StoreUserInfo.xml"); 
}
Note: You have to specify the path of XML file correctly as per your project. In my case, it's D:\Sanju\XMLDb1\StoreUserInfo.xml. It will be different for you. This piece of code will automatically create the child nodes along with its values entered in the text boxes at each click of the submit button.

Step 4

Once you have successfully submitted the records, you will like to see all the submitted records on different web pages but within the same project solution. For that, you add a new page in your project. Now you can display the data from XML file on text box, label or richtext box wherever you desire. In my example, I will use both text box as well as Label controls. Design of my Display page is the same as the above page with an additional Label control.
Note: On the display page, you will be needing one HiddenField control to keep count of the node number before each postback occurs so as to track through the child nodes in the XML file.
display_small.JPG

Step 5

Copy and paste the following code on the Click event of the Show4mXML button:
protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Int32 j = 0;
            Hidint.Value = Convert.ToString(j);
        }
    }
Note: Hidint is the ID of the HiddenField control on the ASPX page.
private int increment()
    {
        string strInput = Hidint.Value;
        int incrValue = Convert.ToInt32(strInput);
        incrValue += 1;
        Hidint.Value = incrValue.ToString();
        return incrValue;

    }
protected void btnShow4mXML_Click(object sender, EventArgs e)
    {
        DataSet ds = new DataSet();
        ds.ReadXml(Server.MapPath("StoreUserInfo.xml"));
        
        Int32 i = increment();
        DataTable dt = ds.Tables[0];
        if (i <= dt.Rows.Count)
        {
            DataRow dr;
            dr = dt.Rows[i-1];
            txtName.Text = dr["name"].ToString();
            txtEmail.Text = dr["email"].ToString();
            txtComment.Text = dr["comment"].ToString();
            Label1.Text = dr["comment"].ToString();
        }
        else
        {
            btnShow4mXML.Enabled = false;
        }
    }

Tuesday, June 26, 2012

PRODUCTS OF ODD NUMBERS IN C++

# include<iostream.h>
# include<conio.h>
void main()
{
      int count,product=1,num;
      cout<<"Enter the odd number";
      cin>>num;
      for(count=1;count<=num;count+=2)
     {
         product=count*product;
         cout<<"The odd number is"<<count;
      }
         cout<<"The product of odd number is:"<<product;
      getch();
}

Saturday, August 27, 2011

Digital Clock Program in C Language

#include
#include
#include
void main()
{
int h,m,s;
h=0;
m=0;
s=0;
while(1)
{
if(s>59)
{
m=m+1;
s=0;
}
if(m>59)
{
h=h+1;
m=0;
}
if(h>11)
{
h=0;
m=0;
s=0;
}
delay(1000);
s=s+1;
clrscr();
printf("Digital Clock");
printf("HOUR: MINUTE: SECOND\n");
printf("%d: %d: %d",h,m,s);
}
getch();
}

Monday, March 28, 2011

Http Cookies

1.It's a named value page just like a variable but which has the ability to automatically travel between every request and response.
It's a concept of http which web browser, web server all will follow but more maintained by browser. Cookies are designed to be client side i.e browser side.