4 Nov 2009

SQL SERVER 2005- Error 18456: login failed for user

SQL SERVER 2005- Error 18456: login failed for user ' Computer name\ UserName'
This error happens when I run Microsoft SQL Server 2005 at first time with windows vista; I login using SQL Server authentication that was successed, but when I tried to login using windows authentication that was failed following by error message



To fix this problem
Following next steps:
1. Login using SQL Server authentication.
2. Security>> Logins >> New Login



3. In General
Login name= Computer name\ UserName
Select windows authentication



4. In Server Roles
Select sysadmin
>> ok



Now, login using windows authentication that will login.

20 Oct 2009

SQL Server 2oo8: Error 1326

This error happens when you want to connect to another server, due to the instance name does not exist and that SQL Server is configure to allow remote connection; the SQL Server could not connect following by error message



To fix this problem

Following next steps:
1-Control panel >> double click on firewall windows >> Exceptions tab>> add port.



2-Make port for SQL:
Name:SQL
Port:1433
>>ok



3-finally, a port appears.
Click ok.

19 Oct 2009

re-creation table in sql server 2008

How can we save changes that require table re-creation in sql server 2008?
When you work on sql server 2008 at first time to create table then want to change the type of field or rename.. ,after that you want to save, that will following by error message



To fix this problem
Following next steps:
1.Tools>>Options



2.Designers>>click on Table and Database Designers>>unchecked prevent saving changes that require table re-creation >>ok



Then you can change anything entire the table

1 Oct 2009

Convert From SQL Server 2005 to SQL Server 2008

I had tried to attach database in SQL Server 2008 which I was created it in SQL Server 2005, but the error happened when I added the .mdf file followed by error message



Then I imported the database from SQL Server 2005 to SQL Server 2008 through SQL Server 2008 that it works.
To Convert From SQL Server 2005 to SQL Server 2008
Following next steps:
1. Start >> all programs >>Microsoft SQL Server 2008 >> import and export data(64-bit)




2. SQL Server Import and Export Wizard appears
Click next.



3. Choose a data source
Data source: Select Microsoft OLEDB Provider for SQL Server.
Server Name: write the name of source server.
Authentication: choose Use SQL Server authentication, and write user name and password.
Database: Select the database name.
Click next.



4.choose a destination
Data source: Select SQL Server Native client 10.0.
Server Name: write the name of destination server.
Authentication: choose Use SQL Server authentication, and write user name and password.
•Database: Select the database name



0r if you want to create a new database click on new.
Write the name of new database >>ok
Click next.



5.specify table or query
Click next.



6.select source tables and views
Click next.



7. Save and run package
Select Run immediately >>click next.



8.to complete this wizard >>click finish



9.finally click on close

7 Sept 2009

SQL SERVER 2008-Error 916

SQL SERVER 2008- Error 916: The server principal "username" is not able to access the database "EmployeesDB" under the current security context.

This error happens when you want to connect remotely with database in SQL Server 2008 Management Studio which is following by error message



Notice: if you connect with SQL Server 2005 Management Studio, it will connect with database(no error message)

To fix this problem

Following next steps:

1. In Object Explorer, click on Databases.

2. View Object Explorer Details
(F7) or View >> Object Explorer Details.

3.Right click on the column headers and deselect
collation


4.Refresh Databases

Open Table in SQL Server 2008 Management Studio

SQL Server 2008 Management Studio replaced open table by Edit Top 200 Rows.
Right click on a table >>Edit Top 200 Rows



You can change Edit Top 200 Rows by following next steps:
Tools >> Options >> SQL Server Object Explorer >> Commands

First notice about SQL Server 2008 Management Studio

When I was started using SQL Server 2008 Management Studio, the first things I noticed are Select Top 1000 Rows and Edit Top 200 Rows replaced by Open Table in SQL Server 2005 Management Studio

9 Aug 2009

Convert ByteArray To Image

Image Table
CREATE TABLE [dbo].[Image_Table]
(
[Img_ID] [bigint] IDENTITY(1,1) NOT NULL,
[Image_Name] [image] NULL,
)


How To Convert Byte Array To Image
When you want to take image from database.It must change byte array to image to show it.
The next function convert byte array to image :

public Image byteArrayToImage(byte[] bArray)
{
MemoryStream ms = new MemoryStream(bArray);
Image Img = Image.FromStream(ms);
return Img;
}


How To Show Image
call the function:

pictureBox1.Image=byteArrayToImage((byte[])dr["Image_Name"]);

dr["Image_Name"]: is a data reader .it takes values from database.

Convert Image To ByteArray

Image Table
CREATE TABLE [dbo].[Image_Table]
(
[Img_ID] [bigint] IDENTITY(1,1) NOT NULL,
[Image_Name] [image] NULL,
)


How To Convert Image To Byte Array
When you want to save image in database.It must save it as byte array.
The next function convert image to byte array:

public byte[] imageToByteArray(System.Drawing.Image img)
{
MemoryStream ms = new MemoryStream();
img.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
return ms.ToArray();
}

17 Jun 2009

Problems in App_Code

There are many properties don't exist in App_Code pages.

Session in App_Code
when we use Session in App_Code following by error message
The name 'Session' doesn't exist in the current context
To fix this problem write next line in C#.net 2005
System.Web.HttpContext.Current.Session["SessionName"] = value;

Response in App_Code
when we use Response.Redirect in App_Code following by error message
The name 'Response' doesn't exist in the current context
To fix this problem write next line in C#.net 2005
System.Web.HttpContext.Current.Response.Redirect("Page.aspx");

11 Jun 2009

How can take backup from table...

How can take backup from table to another table in the same database?
We can use SELECT INTO to take backup.

We can select:
1.One column or more
select column1
into NewTable
from OldTable



2.All columns

select *
into NewTable
from OldTable


Also we can use where
select *
into NewTable
from OldTable
where column1='Haia'

10 Jun 2009

.net code converter (C# - VB.NET)

I found site that it easy way to convert code, just paste code then it will automatically convert:

1.Convert C# to VB.NET
csharp-to-vb

2.Convert VB.NET to C#
vb-to-csharp

4 Jun 2009

Computer until sleep

I was looking for sms then i found these cute pictures. Are they reflected lazy or serious people at work?





























27 Apr 2009

AppSettings In web.config

The appSettings is an element of a web.config template to store connection strings needed to run the application.


• Put The next code in aweb.config



• How to call the AppSettings in C# ?
Using(SqlConnection con=new SqlConnection(ConfigurationManager.AppSettings["connectionString"].ToString()))
{
Con.Open();
.
.
.
}

19 Mar 2009

Timestamp With time zone and without time zone


TIMESTAMP without time zone is displayed at the same format as DATETIME,and its format is 'YYYY-MM-DD HH:MM:SS'.

TIMESTAMP with time zone is displayed datetime and time zone ,and its is 'YYYY-MM-DD HH:MM:SS ZZZ'.


How to create timestamp in Postgre Sql ?

1.With time zone

CREATE TABLE MyProject."Employee"

(

IDX bigint NOT NULL,

Name character varying(64) NOT NULL,

RegisterDate timestamp with time zone NOT NULL,

CONSTRAINT Employee_pkey PRIMARY KEY (idx)

)

ALTER TABLE MyProject."Employee"OWNER TO postgres;


2.Without time zone

CREATE TABLE MyProject."Employee"

(

IDX bigint NOT NULL,

Name character varying(64) NOT NULL,

RegisterDate timestamp without time zone NOT NULL,

CONSTRAINT Employee_pkey PRIMARY KEY (idx)

)

ALTER TABLE MyProject."Employee"OWNER TO postgres;


How to insert timestamp column in Postgre Sql(database) with C#.NET 2005?
1.With time zone

NpgsqlConnection NpgCon = new NpgsqlConnection(String.Format("Server={0};Port={1};" +
"User Id={2};Password={3};Database= postgres;",
txtServerName.Text,
txtPort.Text, txtUserID.Text, txtPassword.Text););

NpgsqlConnection NpgCon = new NpgsqlConnection(NpgCon );
try
{
NpgCon.Open();

string txtCommand;

txtCommand="INSERT INTO MyProject."Employee"(IDX , Name, RegisterDate )VALUES (" + txtEmpID.Text + ",'" + txtEmpName.Text + "','" + DTEnrollmentdate.Value.ToString("yyyy-MM-dd hh:mm:ss zzz") + "')";
NpgsqlCommand cmd = new NpgsqlCommand(txtCommand, NpgCon);
cmd.ExecuteNonQuery();
}
catch (System.Exception ex)
{
MessageBox.Show("Error: " + ex.Message);
return;
}
finally
{
if (NpgCon.State == ConnectionState.Open)
NpgCon.Close();
}


2.Without time zone

NpgsqlConnection NpgCon = new NpgsqlConnection(String.Format("Server={0};Port={1};" +
"User Id={2};Password={3};Database= postgres;",
txtServerName.Text,
txtPort.Text, txtUserID.Text, txtPassword.Text););

NpgsqlConnection NpgCon = new NpgsqlConnection(NpgCon );
try
{
NpgCon.Open();

string txtCommand;

txtCommand="INSERT INTO MyProject."Employee"(IDX , Name, RegisterDate )VALUES (" + txtEmpID.Text + ",'" + txtEmpName.Text + "','" + DTEnrollmentdate.Value.ToString("yyyy-MM-dd hh:mm:ss") + "')";
NpgsqlCommand cmd = new NpgsqlCommand(txtCommand, NpgCon);
cmd.ExecuteNonQuery();
}
catch (System.Exception ex)
{
MessageBox.Show("Error: " + ex.Message);
return;
}
finally
{
if (NpgCon.State == ConnectionState.Open)
NpgCon.Close();
}

16 Mar 2009

Connection string for Postgre SQL in C#.NET 2005


Connection string for Postgre SQL in C#.NET 2005 by Npsql

Npgsql

Type: .NET Framework Class Library
Usage: Npgsql.NpgsqlConnection

The Npgsql is based to exist this library (original version) in your project references.
Then define it in your class as next step:

using Npgsql;

How to use that

try
{
NpgsqlConnection NpgCon = new NpgsqlConnection(String.Format("Server={0};Port={1};" +
"User Id={2};Password={3};Database= postgres;",
txtServerName.Text,
txtPort.Text, txtUserID.Text, txtPassword.Text););

NpgCon.Open();
.
.
.
NpgCon.Close();

}
catch (Exception msg)
{
MessageBox.Show(msg.Message);
throw;

}

8 Feb 2009

Do you know that



Windows logo button

This Article is written with English Language and Arabic language.

(هذا الموضوع كتب باللغتين العربية والإنجليزية)

First: English language

You can shortest your time by using keyboard abbreviation that become doing events quickly.

There are many uses for windows button:

1. Press windows logo button + Break button

It will display System Properties

2. Press windows logo button + D button

It will display Desktop

3. Press windows logo button + E button

It will display My computer

4. Press windows logo button + F button

It will display Search Results (about folders and files)

5. Press windows logo button + F button + Ctrl button

It will display Search Results- Computers

6. Press windows logo button + F1 button

It will display Windows Helps

7. Press windows logo button + L button

Lock keyboard (switch user)

8. Press windows logo button + M button

Minimize all windows

9. Press windows logo button + N button

It will display Microsoft Office OneNote

10. Press windows logo button + R button

It will display Run

11. Press windows logo button + U button

It will display Utility Manager

12. Press windows logo button + Y button

It will display Yahoo Messenger

ثانياً: اللغة العربية

تستطيع ان توفر الوقت بإستخدام اختصارات من لوحة المفاتيح، وبالتحديد أتكلم عن زر الويندوز وهناك عدة إستخدامات له:

1. إضغط زر الويندوز + زر Break

تعرض نافذة مواصفات النظام


2. إضغط زر الويندوز + زر D

تعرض سطح المكتب


3. إضغط زر الويندوز + زر E

تعرض نافذة جهاز الحاسوب


4. إضغط زر الويندوز + زر F

تعرض نافدة البحث عن الملفات والمجلدات


5. إضغط زر الويندوز + زر F + زر Ctrl

تعرض نافدة البحث عن جهاز حاسوب داخل الشبكة


6. إضغط زر الويندوز + زر F1

تعرض نافدة مساعدة الويندوز

7. إضغط زر الويندوز + زر L

قفل لوحة المفاتيح

8. إضغط زر الويندوز + زر M

تصغير كل النوافذ

9. إضغط زر الويندوز + زر N

تعرض نافدة Microsoft Office OneNote


10. إضغط زر الويندوز + زر R

تعرض نافدة تشغيل


11. إضغط زر الويندوز + زر U

تعرض نافدة الإدارة


12. إضغط زر الويندوز + زر Y

تعرض نافدة الياهو ماسنجر