Posts

Azure sp_execute_remote / Cross Database query in Sql Azure.

Cross database query is not allowed in Sql Azure. Rather Azure has applied a different logic to use the same. Please check my article before proceeding with "sp_execute_remote " http://an-it-solution.blogspot.in/2017/01/sql-azure-select-from-another-database.html You need to create a SP in " DbCustomers"  with the name of " LogEvents_Insert" which will be called by following query. The below query will execute in " DbPayments  " and insert data into "LogLogin" of " DbCustomers" EXEC sp_execute_remote @data_source_name  = N' DbUtilityLogging_Datasource ', @stmt = N'LogEvents_Insert @LoginID', @params = N'@LoginId nvarchar(50)', @LoginID='narender90'

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 ...

How to add Primary Key and Auto Increment on different fields of MySql

 Normal code generated by MySql:- CREATE TABLE `categorymaster` (   ` CategoryID ` int(11) NOT NULL AUTO_INCREMENT,   ` Category ` varchar(200) DEFAULT NULL,   `IsActiv` int(11) DEFAULT NULL,   `ImagePath` varchar(200) DEFAULT NULL,   `DisplayOrder` int(11) DEFAULT NULL,   PRIMARY KEY (` Category `) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; In the above data stucture I want to make the " Category " as Primary Key and " CategoryId " as Auto Increment. But Table Wizard always give errors so, I decided to write my own Statement. Following is the statement which will create perfect structure according to my requirement. DROP TABLE `dbname`.`categorymaster`; CREATE TABLE `categorymaster` (   `CategoryId` int(11) unsigned NOT NULL AUTO_INCREMENT,   `Category` varchar(200) DEFAULT NULL,   `IsActiv` int(11) DEFAULT NULL,   `ImagePath` varchar(200) DEFAULT NULL,   `DisplayOrder` in...

How to create User Login in Sql Server 2005/2008

Image
How to create User Login in Sql Server 2005/2008 Note - You must be a member of "system admin" to create a new user or database. Following is the steps to create user login in database for database level security :- Step 1 . Open Sql Server >> Enter User Name >> Enter Password >> Click Connect Step 2 . Open Security >> Logins >> Right Click >> New Login Step 3. Enter login name >> Select Radio button "Sql Server Authentication" >>Enter password>>Enter confirm password>> Un-Check Enforce password policy >> Click Ok Step 4. Right click on Databases >> Click new database Step 5. Enter Database name>> Owner "<default>" >> Click Ok Step 6 . Open Newly created database (My Case it is Test)>> Security>> Users>> Right click on dbo >> New users. Step 7. Enter user name>> Login name >> default schema...

How to Expose/Access Sql Server to Internet

Image
Task - Expose Sel Server to Internet or Remote Access via IP OS - Windows Server 2008 R2 Sql Version - Sql Server 2008 R2 To expose the server to internet we need open port for sql server (default port is 1433) To open a port in the Windows firewall for TCP access 1. On the Start menu, click Run, type WF.msc, and then click OK. 2 . In the Windows Firewall with Advanced Security, in the left pane, right-click Inbound Rules, and then click New Rule in the action pane (upper right corner). 3. In the Rule Type dialog box, select Port, and then click Next. 4. In the Protocol and Ports dialog box, select TCP. Select Specific local ports, and then type the port number of the instance of the Database Engine, In my case we are using the default which is 1433. Click Next. 5. In the Action dialog box, select Allow the connection, and then click Next. 6. In the Profile dialog box, I am going to Leave Domain turned on and turn private and public off. Then click Next. 7. In the Name d...

Server Application Unavailable IIS Error

Image
Generally the cause of Server Application Unavailable is the .net framework. Error Snapshot For ex. one of our site is in version 1.1 and the recently added site is in 2.0 or later or any other different versions running on the IIS. How to Resolve:- We need to create a new application pool on the IIS and assign the same to the version of the site. Following image illustrates how to check the version of site. For ex. Pool3_5 for version 3.5 and  Pool4_0 version 4.0 . Following image illustrates how to create new Pool. Step 1: Step 2: Step 3:  You can also verify the IIS logs to locate the issue.

How to make a site default on IIS 6 Windows Server 2003

Image
While setting up an new Web server with Windows Server 2003 and IIS 6. I have to set up my own custom domain (for ex. myname.com) as the default site on IIS. Means if I will run the server from IP my custom domain has to run. The process is so, easy we need to setup few things in custom site. Right click on Site>>Properties>>WebSite>>Click on Advnaced Button>>Leave the "Host header value" to be blank. Please refer the image..

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 set focus on Table row using Javascript

We are developing Application for Google Smart TV and all is going well. We are using Table, Div or some other elements which cannot be focused on using .focus() of java script. We have used Table to show data in one of our page. Our target is to set the focus on first element of table i.e. first row. We tried different solutions suggested on web but nothing worked. All the posts are suggesting to use focusable controls like text box, check box etc. Finally we found solution on http://groups.google.com/group/mozilla.dev.tech.css/browse_thread/thread/42591922d95c6399 In the post "Stanimir Stamenkov" has used a term "if you just define a 'tabindex' on the element it becomes focusable" I assigned "tabindex" property to table row and then used .focus() and the focus reached to row. Hope this will help all who are looking for such nice solutions.

How to allow special characters in URL or query string

I am using asp.net 4.0 with Sql server. I have an requirement to pass special characters in URL query string. for example my URL need to be like http://mysite.com/default.aspx?a=xyx(abc) In the above URL my special character is "(" and ")". While development I have not faced any issue but as I uploaded the files to serve it start giving error 404 (page not found) where ever I have use "(" or ")" special characters. When I started searching I have tried many solutions. but nothing works for me. Then on some site some one has sugested to check IIS log. When I checked the log I found that I have Installed Microsoft URL Scan 3.1 on my server which is filtering the URL. So, I need to allow "(" and ")" on my server so, I decided to allow there characters in my URL. So, to add exception to URL Scan 3.1 you need to open urlscan.ini which you can find in "%windir%\system32\inetsrv\urlscan\" You can use 2 section...

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 resolve "crdb_adoplus.dl" issue

With the launch of VS 2010, we start using VS 2010 and used the new improved IDE and features of VS 2010. While woring with a windows based application we have requirement to use Crystal Report. We are able to add and design a new Crystal Report without facing any problem. After writing the code to show data, we start getting a unique problem of "crdb_adoplus.dl". We searched for many solution and finally find the solution. We added the following attributes in app.config <startup useLegacyV2RuntimeActivationPolicy="true"> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/> </startup> So, the final app.config will be :- <?xml version="1.0" encoding="utf-8" ?> <configuration> </connectionStrings> <startup useLegacyV2RuntimeActivationPolicy="true"> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/> ...

How to set max limt of File Upload in Asp.net

Many times I faced the same problem with all my applications, that is Max size of file to be uploaded to server. By default, the maximum size limit of a file to be uploaded to a server using the ASP.NET FileUpload control is 4MB. You cannot upload anything that is larger than this limit. If you wants to upload a file more the size of 4 MB which is by default, you have to make some changes in the application's web.config: <configuration> <system.web> <httpRuntime maxRequestLength="xxx" /> </system.web> </configuration> Below is the small description of the parameters attributes. maxRequestLength - Attribute limits the file upload size for ASP.NET application. This limit can be used to prevent denial of service attacks (DOS) caused by users posting large files to the server. The size specified is in kilobytes. As mentioned earlier, the default is "4096" (4 MB). Max value is "1048576" (1 GB) for .NET Framework ...

How to Get/Set date time according to Different Time zones in C#

Image
Download code example In an Asp.net application I have developed a Forum in which I have requirement to show date and time according to the time zone of PC on which it is running, I had searched for too many examples on but all are using too complex java scripts and other methods to convert time into local time zone. Finally I decided to make my own solution for this problem My solution is using “TimeZoneInfo” to convert the data to local time zone, this class allow me to convert time according to any time zone, but again I got another problem which is how to take time zone of browser. Again I search on net and finally come out with a code. <script language="javascript" type="text/javascript">     function genarateDateValue()     {                      var d = new Date()             ...

How to zip a file or folder using C#

Image
Download code example I had searched a lot to make files zip using c#, all the solution provided only support to zip a single file but my requirement is to zip a directory selected by used, I had tried so many utilities but unfortunately all does not works for me. Finally I found a solution which is using Java utility to zip file. This solution is quite easy to implement and debug. To implement this solution you need to add reference of “C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\vjslib.dll” to your application.

How to pass server values to Javascript using Eval()

In my application I have a target to show message if user does not have permission to navigate to another page. I can do this by using server code but it will make a round trip to server and make a bad user experience so, I decided to use java script. Following is the function of Java Script <script language="javascript" type="text/javascript"> function func_Message(obj) { if (parseFloat(obj)>0) { return true; } else { alert("Please assign a value before viewing the details"); return false; } } </script> And following is the code of Link Button from where I am passing value to Java Script Function <asp:LinkButton ID="lnk_Details" runat="server" Text="Details" CommandArgument='<%# Eval("festi_id") +"~" + Eval("user_id") %>' CommandName="ViewDet...

Disbale JIT in .net / Application level Exception handling in .net

Image
Download Code Example I was developing windows application for a well known company of World. This application was in C#.net 2005. As per requirement I have to show user defined message whenever an Exception occurs in the application. The answer is very simply write a simple Try{},Catch{} statement to handle exception. Suppose I have a code of 1000 line unwanted code and error handling creates extra thread while executing the application. I had search on the internet and found a solution to disable the JIT debugger. It works but still it is showing the application information related to functions etc. used in the code. Now, a major issue had risen from client, i.e. he don’t want to show JIT information to user he wants to show his own message whenever any Exception occurs. Offf…. Now that’s the task to which needs to done. I cannot use Try{},Catch{} as this decrease the application performance. Finally I came to the solution. I had wired an event with application to handle applicatio...

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, ...

C# too many database connections error

Every database is having some number of connection limits which you can increase up to an extend. But database can support up to an number of connections. This error occurs when we open a connection and forget to close that. Verify each line of your code and make sure you had closed the connection after completing your database operations. I had faced this error in C# My sql application. I had crossed verify my code and find a code where I am not closing my connection after completing my operations. I had simply write connection.Close(); and it had worked.

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()) ...