Posts

Showing posts with the label Sql server

Sql azure select from another database / Cross Database connection

Cross database query Sql Azure Azure cross database query performance sql azure select from another database reference to database and/or server name in is not supported in this version of sql server. All the above statements are reference to the issue we face while shifting data from Sql Server to Azure Database. While using Sql Server (Any version) we can reference any database with in Sql server according to user rights assigned to user. We can use statements like "select * from db1.dbo.customers" But now in Sql Azure the system and terminology has changed. Now, azure has new concept of External Tables  and sp_execute_remote  in introduced. Now we need to know the who is who in Azure. External Tables = "Is for Select" sp_execute_remote="Execute External Store Procedures" Before proceeding. Please create 2 azure databases as per your choice. Here I am naming them as. DbCustomers and DbPayments  and keep a reference to them ...

Windows Event Starting up database DatabaseName

Image
Configuration:- Windows Server 2003 R2 32 bit Sql Express 2008 R2 While checking for server event as a part of maintenance we a information which is occuring after every 1-10 seconds the information is Event "Starting up database DatabaseName" We found the solution and implemnted the same. You need to open "Sql Express Management Studio>>Database>>Properties>>Options>>Auto Close" and set it to false. For more information on this property, please refer http://blogs.msdn.com/b/buckwoody/archive/2009/06/24/sql-server-best-practices-autoclose-should-be-off.aspx http://msdn.microsoft.com/en-us/library/ms135094%28SQL.90%29.aspx

How to select data from another sql server

We have a target to run a JOB on server to import data from another SQL server instance. For example take Server 1 - Main Server 2 - From which we have to import. If you have admin rights on both the servers you can "Link the servers" under "Server Objects>>Linked Servers" Right click on the same and provide all the parameters of server or as an alternate you can run following command. EXEC sp_addlinkedserver @server = 'db1', @srvproduct = 'SQLServer OLEDB Provider',  @provider = 'SQLOLEDB',  @datasrc = 'server2',  @provstr='User Id=sa; Password=abc' The above command parameters:-  @server- An identification name of server. @datasrc- Your server instance name or IP. Your SQL will look like:- Select * from db1.dbname.dbo.tablename If sometimes the server will get changed, the above statement gives you the option to change the user name, password and server at any points of time without effecting the ...

How to alter Auto Increment field in Sql server

It is not possible to remove Auto Increment field using Alter command in Sql Server. What we can use is SET IDENTITY_INSERT Take this following example this creates a table with auto increment field and still insert data to the same. Generally if you try to insert the data into auto increment field it will through error. But if we use SET IDENTITY_INSERT <Table Name>ON it will allow you to insert data into auto increment field. Note: Make sure after completing this operation you set the value to SET IDENTITY_INSERT <Table Name>OFF --Create table and its columns CREATE TABLE [test].[Table_1] ( [Id][int] NOT NULL IDENTITY (1, 1), [Name][nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL); GO ALTER TABLE [test].[Table_1] ADD CONSTRAINT [PK_Table_1] PRIMARY KEY CLUSTERED ([Id]) GO SET IDENTITY_INSERT [test].[Table_1] ON GO INSERT INTO [test].[Table_1] ([Id], [Name]) VALUES (1, 'Narender') GO INSERT INTO [test].[Table_1] ([Id], [Name]) VALUES (3, ...

SQL Function Reference:Oracle vs.SQL Server vs. My SQL Part- III

Date Functions Function - Date addition Oracle - (use +) SQL Server - DATEADD My Sql - Need To Update Function - Date subtraction Oracle - (use -) SQL Server - DATEDIFF My Sql - Need To Update Function - Last day of month Oracle - LAST_DAY SQL Server - N/A My Sql - Need To Update Function -Time zone conversion Oracle - NEW_TIME SQL Server - N/A My Sql - Need To Update Function -First weekday after date Oracle - NEXT_DAY SQL Server - N/A My Sql - Need To Update Function -Convert date to string Oracle -TO_CHAR SQL Server - DATENAME My Sql - Need To Update Function -Convert date to number Oracle -TO_NUMBER(TO_CHAR()) ...

SQL Function Reference:Oracle vs.SQL Server vs. My SQL Part- II

String Functions Function - Convert character to ASCII Oracle - ASCII SQL Server - ASCII My Sql - ASCII Function -String concatenate Oracle - CONCAT SQL Server - (expression + expression) My Sql - CONCAT Function -Convert ASCII to character Oracle - CHR SQL Server - CHAR My Sql - CONCAT Function -Return starting point of character in character string (from left) Oracle - INSTR SQL Server - CHARINDEX My Sql - INSTR Function -Convert characters to lowercase Oracle - LOWER SQL Server - LOWER My Sql - LOWER Function -Convert characters to uppercase Oracle - UPPER SQL Server - UPPER My Sql - UPPER Function -Pad left side of character string Oracle - LPAD SQL Server - N/A My Sql - LPAD Function -Remove leading blank spaces Oracle - LTRIM SQL Server - LTRIM My Sql - LTRIM Function -Remove trailing bl...

SQL Function Reference:Oracle vs.SQL Server vs. My SQL Part- I

Generally the major issue we face while development is the availability of common functions in different database(s). I am facing this issue from last so many years. Then I had start preparing a table for common functions of different database(s). The commonly used databases are Oracle, Sql Server and My Sql. Their is so many other database(s) are also available but commonly I works on these database(s) only. Following is the common list of functions in different database(s):- Math Functions Function - Absolute value Oracle - ABS SQL Server - ABS My Sql - ABS Function - Arc cosine Oracle - ACOS SQL Server - ACOS My Sql - ACOS Function - Arc sine Oracle - ASIN SQL Server - ASIN My Sql - ASIN Function - Arc tangent of n Oracle - ATAN SQL Server - ATAN My Sql - ATAN Function - Arc tangent of n and m Oracle - ATAN2 SQL Server - ATAN2 My Sql - Please Suggest Function - Smallest integer >= value Orac...

Auto Complete Example in Asp.net C# Using JQuery

Image
Download Running Code Supporting JQuery Before writing this post I had written one another post which is using a pure JavaScript to show Auto complete or Auto delete example. My previous example is not using Jquery which is a famous and reliable way to present your data. One of the drawback of my previous example is it will become slow as I have to load a bulk data for auto complete box. I had received many comments on this post, some of them had appreciated and some of them had suggested using Jquery. One of my great readers had given an example of Jquey which I am posting to help you all. So, before posting this example I would like to say thanks to my reader Eng. Mohammed Ibrahim who had suggested and helped me to help others.

How to use Enterprise Library using C#

Summary The Microsoft Enterprise Library is a collection of reusable software components (application blocks) designed to assist software developers with common enterprise development cross-cutting concerns (such as logging, validation, data access, exception handling, and many others). Application blocks are a type of guidance; they are provided as source code, test cases, and documentation that can be used "as is," extended, or modified by developers to use on complex, enterprise-level line-of-business development projects. Some Features While using enterprise library you have to concern about opening and closing connections. This will automatically handle connection pooling and other important errors of connection and database. I had used Enterprise Library 2.0 - January 2006. To use Enterprise Library you required to add reference of following files:- Microsoft.Practices.EnterpriseLibrary.Common.dll Microsoft.Practices.EnterpriseLibrary.Configuration.De...

How to make Human Verification Code or Image Verification Code in c#.net

Now, on many sites we can see image verification or human verification codes. By entering the verification code shown on the web page when a user sign up, the web site or application can prevent automated registrations. This reduces system loads and ensures better performance and security of web site or application. This tutorial will show you how to create the randomly generated verification code in ASP.NET 2.0 and C#. Now, questions arises how to make these code. Now, time to say thanks to .net who had given a wonderfull library with the name of System.Drawing. Before stating any thing import System.Drawing. Copy this code: Using System.Drawing; In order to create a random verification code, we create a method called CreateRandomCode at first public string CreateRandomCode(int codeCount) { string allChar = "0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z"; string[] allCharArray = allChar.Split(','); string randomC...

What is SQL Injection Attack Part -II

Recommended reading part I Use Type-Safe SQL Parameters The Parameters collection in SQL Server provides type checking and length validation. If you use the Parameters collection, input is treated as a literal value instead of as executable code. An additional benefit of using the Parameters collection is that you can enforce type and length checks. Values outside the range will trigger an exception. The following code fragment shows using the Parameters collection: SqlDataAdapter myCommand = new SqlDataAdapter("AuthorLogin", conn); myCommand.SelectCommand.CommandType = CommandType.StoredProcedure; SqlParameter parm = myCommand.SelectCommand.Parameters.Add("@au_id",SqlDbType.VarChar, 11); parm.Value = Login.Text; In this example, the @au_id parameter is treated as a literal value instead of as executable code. This value is checked for type and length. If the value of @au_id does not comply with the specified type and length constraints, an exception will be thrown....

What is SQL Injection Attack

When first time I had heard about SQL Injection attack, I got afraid what the thing about, who can even insert, select and drop my tables from my database. After searching on internet and visiting many of website I came to some of the conclusions. What is SQL injection attack? SQL injection is an attack in which malicious code is inserted into strings that are later passed to an instance of SQL Server for parsing and execution. Any procedure that constructs SQL statements should be reviewed for injection vulnerabilities because SQL Server will execute all syntactically valid queries that it receives. Even parameterized data can be manipulated by a skilled and determined attacker. The primary form of SQL injection consists of direct insertion of code into user-input variables that are concatenated with SQL commands and executed. A less direct attack injects malicious code into strings that are destined for storage in a table or as metadata. When the stored strings are subsequently conca...