European Windows 2012 Hosting BLOG

BLOG about Windows 2012 Hosting and SQL 2012 Hosting - Dedicated to European Windows Hosting Customer

ASP.NET Web Pages 3.1 with Free ASP.NET Hosting - HostForLIFE.eu :: How to Insert Data Page

clock April 17, 2015 09:42 by author Rebecca

In this post, I will tell you how to insert data page with example code in ASP.NET Webpages 3.1.

Follow these steps to insert data page:

Step 1

Click Databases. then click on Home in the ribbon menu, and Click on New Query. Let's copy this following code:

CREATE TABLE Games
(
Id INT NOT NULL PRIMARY KEY IDENTITY,
GameName NVARCHAR(200) NOT NULL,
ReleaseDate DateTime NOT NULL,
mTitle NVARCHAR(200) NOT NULL,
mDescription NVARCHAR(200) NOT NULL,
Text nText NOT NULL
);

Step 2

Click Execute.

Now, you have created a new table and a few columns so we can perform our CRUD operations. In the Create page copy the following:

@{
var GameName = "";
DateTime ReleaseDate = DateTime.UtcNow;
var mTitle = "";
var mDescription = "";
var Text ="";

Then you have created 5 variables which you will use to collect the user-entered data and then insert the data into a database. The second variable is a DateTime data type. The second column in the database is for DateTime. The user will not have to specify the ReleaseDate, as it has been set as the current UTC date and time.

if (IsPost)
{
    GameName = Request["GameName"];
    mTitle = Request["mTitle"];
    mDescription = Request["mDescription"];
    Text = Request.Unvalidated("Text");
 
    Validation.RequireFields("GameName", "mTitle", "mDescription", "Text");


var SQLINSERT = "INSERT INTO Games (GameName, ReleaseDate, mTitle, mDescription, Text) VALUES (@0, @1, @2, @3, @4)";

When the user submits the data we request the values from the HTML elements. The Request.Unvalidated allows the user to type anything they like. By default, ASP.NET will not allow you to type HTML and JavaScript; this is a security measure to avoid XSS attacks.

The validation ensures that no field is left blank. You have to separate each field with a comma. Now, SQLINSERT is our database command. You can specify the column names and then the values which will be inserted. When we use @0, @1 we pass the data as parameters; this is the safest way to do this as it avoids XSS attacks. Always pass the data like this:

    if (Validation.IsValid())
    {
        try
        {
            var db = Database.Open("StarterSite");
            db.Execute(SQLINSERT, GameName, ReleaseDate, mTitle, mDescription, Text);
            Response.Write("Data Saved!");
        }catch (Exception ex)
        {
            Response.Write(ex.Message);
        }
    }
 
}
 
}


Lastly, we ensure that the data entered is valid, and then use a try catch block to execute the database command. The db.Execute method takes two arguments (string command, param object[] args); the second argument is basically the parameters. When you specify the parameters in the Execute method you need to make sure that it is in the right order, otherwise you will get errors. For example, try entering:

db.Execute(SQLINSERT, GameName, mTitle, ReleaseDate,  mDescription, Text);

This will flag an error because the second column expects a data type of DateTime. It is good practise to keep the order of the columns as they appear in the table.

Full HTML Script

<form method="post">
<fieldset>
<legend>Insert Data</legend>
@Html.ValidationSummary(true)
<div>
<label>Game Name</label>
<input type="text" value="@GameName" name="GameName"/>
@Html.ValidationMessage("GameName")
</div>
 
<div>
<label>Meta Title</label>
<input type="text" value="@mTitle" name="mTitle"/>
@Html.ValidationMessage("mTitle")
</div>
 
<div>
<label>Meta Description</label>
<input type="text" value="@mDescription" name="mDescription"/>
@Html.ValidationMessage("mDescription")
</div>
 
 
<div>
<label>Text</label>
<textarea class="ckeditor" name="Text">@Text</textarea>
@Html.ValidationMessage("Text")
</div>
 
<input type="submit"/>
</fieldset>
 
</form>
 
<script src="/ckeditor/ckeditor.js"></script>

One thing that should be explained is the <script> tag. We will use CKEditor for our <textarea>, as this allows us to add HTML styles.

Finaaly, you can run the page and add a new entry, and remember the title for the GameName. Make sure the GameName does not have any spaces or characters; stick with numbers, letters and dashes only.

HostForLIFE.eu ASP.NET WebPages 3.1 with Free ASP.NET Hosting
Try our
ASP.NET WebPages 3.1 with Free ASP.NET Hosting today and your account will be setup soon! You can also take advantage of our Windows & ASP.NET Hosting support with Unlimited Domain, Unlimited Bandwidth, Unlimited Disk Space, etc. You will not be charged a cent for trying our service for the next 3 days. Once your trial period is complete, you decide whether you'd like to continue.



Free ASP.NET Hosting with OWIN Support - HostForLIFE.eu :: How to Self Host the Web API using OWIN Custom Hosting?

clock April 16, 2015 06:47 by author Peter

In this short tutorial, I will tell you how to self-host the Web API, using OWIN custom host. First step that you must do is Add a new Console application as you can see on the below picture.

Next, in order to make a web API and use OWIN custom host, we tend to add references to Microsoft.AspNet.WebApi.OwinSelfHost, using the Nuget Package Manager. this may not only add the references for the web API however also the OWIN components, along with the opposite needed dependencies.

Add a replacement web API controller class. we tend to take away all the methods and add an easy GET method to get the sum of two random numbers.

Add a new class named Startup.cs. this can be as per the OWIN specifications. Use the HttpConfiguration class to make the web API routing template and add it to the request pipeline using the appBuilder.UseWebApi method, where appBuilder is of type IAppBuilder.

Open the Program.cs file and begin the server using the WebApp.Start method, specifying the StartUp class because the entry point for the settings needed. this is the OWIN specification of starting the server within the custom host.

Now simply run the application and the server is started.

To test the Web API, we’ll use the Chrome browser Postman extension. So type the URL of the Web API that we specified in the Program.cs and Send the request. See the results received as you can see on the following picture:

Free ASP.NET Hosting with OWIN Support

Try our Free ASP.NET Hosting with OWIN Support today and your account will be setup soon! You can also take advantage of our Windows & ASP.NET Hosting support with Unlimited Domain, Unlimited Bandwidth, Unlimited Disk Space, etc. You will not be charged a cent for trying our service for the next 3 days. Once your trial period is complete, you decide whether you'd like to continue.



SQL Reporting Service with Free ASP.NET Hosting - HostForLIFE.eu :: How to Fix an Error on Reporting Services “The report server installation is not initialized” ?

clock April 14, 2015 06:40 by author Peter

In this tutorial, let me tell you about How to Fix an Error on Reporting Services “The report server installation is not initialized” ? I had an undertaking for restoring the Reporting Services database from a live situation to a test domain.  Directly after the effective restore, I took  opening the Report Manager site and I was given the error "The report server establishment is not introduced. (rsReportServerNotActivated)". As you can see on the following picture:

SOLUTION

This is a result of the  mismatch in the encryption key. To alter this, either restore the encryption key from the live environment or erase the encryption key from the restored reporting administrations database.  The restoration or cancellation of encryption key could be possible by utilizing the Reporting Services Configuration Manager.

I hope this tutorial works for you!

SQL Reporting Service with Free ASP.NET Hosting
Try our SQL Reporting Service with Free ASP.NET Hosting today and your account will be setup soon! You can also take advantage of our Windows & ASP.NET Hosting support with Unlimited Domain, Unlimited Bandwidth, Unlimited Disk Space, etc. You will not be charged a cent for trying our service for the next 3 days. Once your trial period is complete, you decide whether you'd like to continue.



ASP.NET Web Pages 3.1 Hosting - HostForLIFE.eu :: First Look at ASP.NET Web Pages

clock April 13, 2015 06:56 by author Rebecca

As you know, ASP.NET comes in three types: MVC, Web Forms and WebPages.
1. Web Forms - This is the classic ASP.NET framework; it has all the server side controls and is used for creating dynamic websites. It does have a steep learning curve and controls most of the mark-up so there is little control. It is event-driven and is good for RAD (Rapid Application Development).

2. MVC - Model-View-Controller, this framework also has a steep learning curve, however, it is ideal for developers who like to have control over their websites and like to separate logic and UI. It is ideal for team based work.
3. Web Pages – This is the easiest of all and is what you’ll be learning. It uses the Razor View Engine and is easy to learn providing you have a good understanding of HTML, CSS, JavaScript and either C# or Visual Basic.

Today, I will introduce to you about ASP.NET WebPages.

ASP.NET WebPages is a lightweight web framework for creating rich websites using Microsoft C# or Visual Basic. The framework is the ideal starting place for newcomers to ASP.NET, as well as experienced developers who wish to get into ASP.NET development.If you're interested in learning basic programming, ASP.NET WebPages gives you the different feels between any JavaScript in a web page that you've ever written before.

You can use ASP.NET WebPages to create dynamic web pages. A simple HTML web page is static; its content is determined by the fixed HTML markup that's in the page. Dynamic pages like those you create with ASP.NET Web Pages let you create the page content on the fly, by using code. Dynamic pages let you do all sorts of things too. You can ask a user for input by using a form and then change what the page displays or how it looks. You can take information from a user, save it in a database, and then list it later. You can send email from your site. You can interact with other services on the web (for example, a mapping service) and produce pages that integrate information from those sources. Most examples of using ASP.NET Web Pages with Razor syntax use C#. But the Razor syntax also supports Visual Basic. To program an ASP.NET web page in Visual Basic, you create a web page with a .vbhtml filename extension, and then add Visual Basic code.

You'll need to use IDE when working with Web Pages and the ideal IDE that will compatible with ASP.NET WebPages is Microsoft WebMatrix. Microsoft WebMatrix is a small IDE which was released alongside ASP.NET Web Pages. WebMatrix is a tool that integrates a web page editor, a database utility, a web server for testing pages, and features for publishing your website to the Internet. WebMatrix is free, and it's easy to install and easy to use. It also works for just plain HTML pages, as well as for other technologies like PHP.

WebMatrix contains:

1. Web Pages examples and templates
2.A web server language (Razor using VB or C#)
3. A web server (IIS Express)
4. A database server (SQL Server Compact)
5. A full web development framework (ASP.NET)

With WebMatrix you can start from scratch with an empty web site and a blank page, or build on open source applications from a "Web Application Gallery". Both PHP and ASP.NET applications are available, such as Umbraco, DotNetNuke, Drupal, Joomla, WordPress and many more. WebMatrix also has built-in tools for security, search engine optimization, and web publishing. The skills and code you develop with WebMatrix can seamlessly be transformed to fully professional ASP.NET applications.

But, you don't actually have to use WebMatrix to work with ASP.NET Web Pages. You can create pages by using a text editor too, for example, and test pages by using a web server that you have access to.

HostForLIFE.eu ASP.NET WebPages 3.1 Hosting
HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes. We have customers from around the globe, spread across every continent. We serve the hosting needs of the business and professional, government and nonprofit, entertainment and personal use market segments.



OWIN & Katana.NET Hosting - HostForLIFE.eu :: How to Build a Simple Server using OWIN and Katana

clock April 10, 2015 07:39 by author Rebecca

This article will show you how easy to build a simple server using OWIN and Katana Project. Usually, you use HTML, JavaScript, and CSS files over HTTP from a .NET desktop application to run the scenario code that you've created. But, Katana makes it easier to run you scenario code.

Here is an example using a console application:

First, use NuGet to install a couple packages into the project.

install-package Microsoft.Owin.StaticFiles
install-package Microsoft.Owin.SelfHost

The source for the entire application is 17 lines of code, including statements:

using System;
using Microsoft.Owin.Hosting;
using Owin;
 
namespace ConsoleApplication5
{
    class Program
    {
        static void Main(string[] args)
        {
            var url = "http://localhost:8080";
            WebApp.Start(url, builder => builder.UseFileServer(enableDirectoryBrowsing:true));          
            Console.WriteLine("Listening at " + url);
            Console.ReadLine();
        }
    }
}

Then, the FileServer middleware will serve files from the same directory as the executable.

But, if you don’t want to use the default location, you can provide your own IFileSystem and serve files from anywhere. Katana currently provides two implementations of IFileSystem – one to serve embedded resources and the other one serve files from the physical file system. You can construct a PhysicalFileSystem for an arbitrary location on the hard drive, like this following code below:

static void Main(string[] args)
{
    var url = "http://localhost:8080";
    var root = args.Length > 0 ? args[0] : ".";
    var fileSystem = new PhysicalFileSystem(root);
 
    var options = new FileServerOptions
    {
        EnableDirectoryBrowsing = true,
        FileSystem = fileSystem                           
    };
 
    WebApp.Start(url, builder => builder.UseFileServer(options));          
    Console.WriteLine("Listening at " + url);
    Console.ReadLine();
}

The FileServer middleware is actually a composite wrapper around three other pieces of middleware:

  • DefaultFiles (to select a default.html file, if present, when a request arrives for a directory).
  • DirectoryBrowser (to list the contents of a directory if no default file is found).
  • StaticFile (to reply with the contents of a file in the file system).

All three pieces of middleware are configurable through the UseFileServer extension method.

For example, the static file middleware will only serve files with a known content type. Although the list of known content types is extensive, you might need to serve files with uncommon extensions, in which case you can plug a custom IContentTypeProvider into the static files middleware.

public class CustomContentTypeProvider : FileExtensionContentTypeProvider
{
    public CustomContentTypeProvider()
    {
        Mappings.Add(".nupkg", "application/zip");
    }
}


Now the final program looks like the following:

static void Main(string[] args)
{
    var url = "http://localhost:8080";
    var root = args.Length > 0 ? args[0] : ".";
    var fileSystem = new PhysicalFileSystem(root);
    var options = new FileServerOptions();
    
    options.EnableDirectoryBrowsing = true;
    options.FileSystem = fileSystem;       
    options.StaticFileOptions.ContentTypeProvider = new CustomContentTypeProvider();
 
    WebApp.Start(url, builder => builder.UseFileServer(options));          
    Console.WriteLine("Listening at " + url);
    Console.ReadLine();
}

HostForLIFE.eu OWIN and Katana.NET Hosting
HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes. We have customers from around the globe, spread across every continent. We serve the hosting needs of the business and professional, government and nonprofit, entertainment and personal use market segments.



SQL Server 2014 Hosting - HostForLIFE.eu :: How to Handling NULL Character \x00 when Exporting to File Using BCP?

clock April 9, 2015 07:21 by author Peter

In this tutorial, I will show you how to handling NULL Character \x00 when Exporting to File Using BCP in SQL Server.

This article talks about the conduct of the BCP utility when removing information from SQL Server to records and all the more particularly to CSV documents. Imagine that you have the underneath table:

As you can see on the above picture, records 2 and 3 contain null values. Now, you need to export the table contents to CSV using BPC: bcp "SELECT [code],[description],[price] FROM [TestDB1].[dbo].[product]" queryout "c:\tmp\testExtract.csv" -c -C 1253 -t ; -S ".\SQL2K14" -T

And here is the output from the code:

As should be obvious on the above screenshot, the output appears to be correct. The records' NULL value have been supplanted with unfilled strings. Now, consider that the first table, rather than NULL qualities has unfilled strings:

Let's try again to export the new table contents to CSV using BPC:
bcp "SELECT [code],[description],[price] FROM [TestDB1].[dbo].[product]" queryout "c:\tmp\testExtract.csv" -c -C 1253 -t ; -S ".\SQL2K14" –T

And here is the output:

As should be obvious, the unfilled strings have been replaced by NULLs which relate to the hexadecimal character \x00. It appears from the above sample, that the queryout keyword has the same behavior regarding null and empty strings.

Presently, if you are going to nourish the CSV document to another application for parsing and handling it, if the application does not expressly handle conceivable events of the NULL character then most probably an error will be occurred. To this end, dependably have as a top priority the above conduct when extracting data to files using BCP.

HostForLIFE.eu SQL Server 2014 Hosting
HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes. We have customers from around the globe, spread across every continent. We serve the hosting needs of the business and professional, government and nonprofit, entertainment and personal use market segments.



WCF Hosting - HostForLIFE.eu :: Simple Steps to Enable Tracing in WCF

clock April 7, 2015 11:47 by author Rebecca

Tracing mechanism in Windows Communication Foundation is based on the classes that resides in System.Diagnostic namespace. Important classes are Trace, TraceSource and TraceListener. For better understanding, i'm gonna explain to you step by step approach in this WCF Tutorial.

Follow these steps to enable tracing in WCF:

Step 1: Configuring WCF to emit tracing information/Define Trace Source

You will have the following options:

  1.     System.ServiceModel
  2.     System.ServiceModel.MessageLogging
  3.     System.ServiceModel.IdentityModel
  4.     System.ServiceModel.Activation
  5.     System.Runtime.Serialization
  6.     System.IO.Log
  7.     Cardspace

In configuration file, you need define a source to enable this configuration as follows:

<source name=”System.ServiceModel.MessageLogging”>

Step 2: Setting Tracing Level

We have the following available options:

  •     Off
  •     Critical
  •     Error
  •     Warning
  •     Information
  •     Verbose
  •     ActivityTracing
  •     All

And we need to set this tracing level to available options other than default OFF.

In configuration file, we can choose above values for switchValue attribute as follows:

<source name=”System.ServiceModel.MessageLogging”
switchValue=”Information”>

Step 3: Configuring a Trace Listener

For configuring a trace listener, we will add following to config file:

           <listeners>
<add name=”messages”
type=”System.Diagnostics.XmlWriterTraceListener”
initializeData=”d:logsmessages.svclog” />
</listeners>

Step 4: Enabling Message Logging

Follow this code below to enable message logging:

<system.serviceModel>
<diagnostics>
<messageLogging
logEntireMessage=”true”
logMalformedMessages=”false”
logMessagesAtServiceLevel=”true”
logMessagesAtTransportLevel=”false”
maxMessagesToLog=”3000″
maxSizeOfMessageToLog=”2000″/>
</diagnostics>
</system.serviceModel>

NOTES:

logEntireMessage: By default, only the message header is logged but if we set it to true, entire message including message header as well as body will be logged.
logMalformedMessages: this option log messages those are rejected by WCF stack at any stage are known as malformed messages.
logMessagesAtServiceLevel: messages those are about to enter or leave user code.
logMessagesAtTransportLevel: messages those are about to encode or decode.
maxMessagesToLog: maximum quota for messages. Default value is 10000.
maxSizeOfMessageToLog: message size in bytes.

If you put all of the steps together, configuration file will appear like this:

<system.diagnostics>
    <sources>
      <source name=”System.ServiceModel.MessageLogging”>
        <listeners>
          <add name=”messagelistener”
               type=”System.Diagnostics.XmlWriterTraceListener” initializeData=”d:logsmyMessages.svclog”></add>
        </listeners>
      </source>
    </sources>
  </system.diagnostics>
    <system.serviceModel>
      <diagnostics>
        <messageLogging logEntireMessage=”true”
                        logMessagesAtServiceLevel=”false”
                        logMessagesAtTransportLevel=”false”
                        logMalformedMessages=”true”
                        maxMessagesToLog=”5000″
                        maxSizeOfMessageToLog=”2000″>
        </messageLogging>
      </diagnostics>
    </system.serviceModel>

In this case, information will be buffered and not published to file automatically, So, we can set the autoflush property of the trace under sources as follows:

autoflush =”true” />

HostForLIFE.eu WCF Hosting
HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes. We have customers from around the globe, spread across every continent. We serve the hosting needs of the business and professional, government and nonprofit, entertainment and personal use market segments.

 



OWIN & Katana.NET Hosting - HostForLIFE.eu :: First Look at OWIN and Katana Project

clock March 31, 2015 06:26 by author Rebecca

Today, i'm gonna show you how to get started with OWIN and Katana Project. Open Web Interface for .NET (OWIN) is a specification for the interaction between web servers and web applications. It has its roots in the open source community. By decoupling the web server from the application, OWIN makes it easier to create middleware for .NET web development. Also, OWIN makes it easier to port web applications to other hosts, for example, self-hosting in a Windows service or other process. OWIN is a community-owned specification, not an implementation. The implementation of OWIN is called as Katana Project. The Katana project is a set of open-source OWIN components developed by Microsoft.

Katana is a webframework which is really lightweight and much more modular then ASP.NET. ASP.NET applications always include System.Web, which contains all functionality like caching, authorization, etc. Katana is way more modular. It let’s you build a application where you only add the references you really need. Katana lets you compose a modern Web application from a wide range of different Web technologies and then host that application wherever you wish, exposed under a single HTTP endpoint. This provides several benefits:

  • Deployment is easy because it involves only a single application rather than one application per capability.
  • You can add additional capabilities, such as authentication, which can apply to all of the downstream components in the pipeline.
  • Different components, whether Microsoft or third-­party, can operate on the same request state via the environment dictionary.

So, Katana is a flexible set of components for building and hosting OWIN-based web applications. And this post is just a quick start to give you an impression of the power that Katana gives you.

The code below shows how easy is to get started with Katana. Create a new console application and install the nuget package: Microsoft.Owin.SelfHost. And If you now paste the code, you will already have a working website at localhost:8080.

class Program
{
    static void Main(string[] args)
    {
        var url = "http://localhost:8080";
        using (WebApp.Start<Startup>(url))
        {
            Console.ReadLine();
        }
 
    }
}
 
public class Startup
{
    public void Configuration(IAppBuilder app)
    {
        app.Run(x =>
        {
            x.Response.ContentType = "text/plain";
            return x.Response.WriteAsync("Hello world");
        });
    }
}

We define a url and a startup class. The Startup class needs a configuration method in which we can set the run method with a Func on your IAppBuilder. This appbuilder is the “configuration” of your web application and the run method adds a piece of middleware to your OWIN pipeline which doesn’t invoke a next piece of middleware. Look at it at as the endpoint of all the web requests for this  small web application.

The appbuilder also allows you to add more middleware to your OWIN pipeline. If we for instance want to have some middleware that handles cookies we can add it with a few lines of code.

public class CookieMonster : OwinMiddleware
{
    public CookieMonster(OwinMiddleware next) : base(next)
    {
    }
 
    public async override Task Invoke(IOwinContext context)
    {
        context.Response.Cookies.Append("testcookie", "hello world");
        await Next.Invoke(context);
    }
}

And now, we need to inherit from OwinMiddleware, add a constructor and a async Invoke method. In the invoke method we add our cookie (or whatever logic you want) and make it invoke the next middleware down the pipeline. To  plug this middleware into our application, we only need our appbuilder to use it. Just add the following line in your Startup class above the app.Run line and your done!!

app.Use<CookieMonster>();

Now, you have a working Katana Web Application that adds an annoying cookie. Easy right? This was a really simplified example and there is a lot more to Katana.

For the best OWIN and Katana.NET Hosting, HostForLIFE.eu is the right answer!

HostForLIFE.eu OWIN and Katana.NET Hosting
HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes. We have customers from around the globe, spread across every continent. We serve the hosting needs of the business and professional, government and nonprofit, entertainment and personal use market segments.



SQL Server 2014 Hosting Russia - HostForLIFE.eu :: How to Rename Column Name in SQL Server ?

clock March 17, 2015 07:19 by author Peter

In this post, I will tell you about rename column name in In SQL Server. Now, I’ve got a table “tblRename” in which there are the two columns Id and Name.

But by mistake I misspelled Name to “Names” and now I want to change the column name to the correct name -> “Name”. So, how is it possible to rename the column name without dropping the table?

We can use a System Stored Procedure sp_rename.
EXEC sp_rename 'tblRename.Names', 'Name','column'

sp_rename is the Stored Procedure.The first value is the tblRename that is the table in which the column is to be renamed, as in "Names" -> tblRename.Names. The second value is the new segment name that we need to change it to, in other words Name. The third value is the sort and here the sort is segment.
Execute the previous query.

Finally, the column name is now changed to Name. But when we execute our query we get an error message:

Along these lines, if there are any Stored Procedures and scripts indicating this tblRename table in which you have determined the "Names" segment then that Stored Procedure or script won't come being used any longer in light of the fact that now there is no section present with a name "Names". In this way, in the event that you need to change the segment name then do it before making any important Stored Procedures or scripts.

HostForLIFE.eu SQL Server 2014 Hosting
HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes. We have customers from around the globe, spread across every continent. We serve the hosting needs of the business and professional, government and nonprofit, entertainment and personal use market segments.



SQL Server 2014 Hosting UK - HostForLIFE.eu :: Script TSQL Database Level Security

clock March 12, 2015 08:42 by author Peter

Here's a convenient script that is a piece of my tool stash all over I go. Scripts out and identifies basic database level security objects, and creates a TSQL proclamation to reproduce the items. Note that this script just chips away at SQL 2005 or above. This is a long way from an authority script.

I invite to all input on these scripts. I likewise have a server-level security script here.
--Run the below on each database for database-level security. 
SELECT DB_NAME() as Database_Name 
--Database Level Roles
SELECT DISTINCT
     QUOTENAME(r.name) as database_role_name, r.type_desc, QUOTENAME(d.name) as principal_name, d.type_desc
,    TSQL = 'EXEC sp_addrolemember @membername = N''' + d.name COLLATE DATABASE_DEFAULT + ''', @rolename = N''' + r.name + ''''
FROM sys.database_role_members AS rm
inner join sys.database_principals r on rm.role_principal_id = r.principal_id
inner join sys.database_principals d on rm.member_principal_id = d.principal_id
where d.name not in ('dbo', 'sa', 'public') 
--Database Level Security
SELECT     rm.state_desc
     ,   rm.permission_name
    ,   QUOTENAME(u.name) COLLATE database_default
    ,   u.TYPE_DESC
     ,   TSQL = rm.state_desc + N' ' + rm.permission_name + N' TO ' + cast(QUOTENAME(u.name COLLATE DATABASE_DEFAULT) as nvarchar(256))  
FROM sys.database_permissions AS rm
     INNER JOIN
     sys.database_principals AS u
     ON rm.grantee_principal_id = u.principal_id
WHERE rm.major_id = 0
and u.name not like '##%'
and u.name not in ('dbo', 'sa', 'public')
ORDER BY rm.permission_name ASC, rm.state_desc ASC
 --Database Level Explicit Permissions
SELECT     perm.state_desc
    , perm.permission_name
    ,   QUOTENAME(USER_NAME(obj.schema_id)) + '.' + QUOTENAME(obj.name)
       + CASE WHEN cl.column_id IS NULL THEN SPACE(0) ELSE '(' + QUOTENAME(cl.name COLLATE DATABASE_DEFAULT) + ')' END AS [Object]
     , QUOTENAME(u.name COLLATE database_default) as Usr_Name
    ,   u.type_Desc
    , obj.type_desc
   ,  TSQL = perm.state_desc + N' ' + perm.permission_name
           + N' ON ' + QUOTENAME(USER_NAME(obj.schema_id)) + '.' + QUOTENAME(obj.name)
           + N' TO ' + QUOTENAME(u.name COLLATE database_default)
FROM sys.database_permissions AS perm
     INNER JOIN
     sys.objects AS obj
     ON perm.major_id = obj.[object_id]
     INNER JOIN
     sys.database_principals AS u
     ON perm.grantee_principal_id = u.principal_id
     LEFT JOIN
    sys.columns AS cl
     ON cl.column_id = perm.minor_id AND cl.[object_id] = perm.major_id
where
     obj.name not like 'dt%'
and obj.is_ms_shipped = 0
and u.name not in ('dbo', 'sa', 'public')
ORDER BY perm.permission_name ASC, perm.state_desc ASC


Alternately, wrap the entire thing in a msforeachdb:
exec sp_msforeachdb 'use [?];
SELECT DB_NAME() as Database_Name
--Database Level Roles
SELECT DISTINCT
 QUOTENAME(r.name) as database_role_name, r.type_desc, QUOTENAME(d.name) as principal_name, d.type_desc
, TSQL = ''EXEC sp_addrolemember @membername = N'''''' + d.name COLLATE DATABASE_DEFAULT + '''''', @rolename = N'''''' + r.name + ''''''''
FROM sys.database_role_members AS rm
inner join sys.database_principals r on rm.role_principal_id = r.principal_id
inner join sys.database_principals d on rm.member_principal_id = d.principal_id
where d.name not in (''dbo'', ''sa'', ''public'')
--Database Level Security
SELECT  rm.state_desc
 ,   rm.permission_name
    ,   QUOTENAME(u.name) COLLATE database_default
    ,   u.TYPE_DESC
 ,   TSQL = rm.state_desc + N'' '' + rm.permission_name + N'' TO '' + cast(QUOTENAME(u.name COLLATE DATABASE_DEFAULT) as nvarchar(256))  
FROM sys.database_permissions AS rm
 INNER JOIN
 sys.database_principals AS u
 ON rm.grantee_principal_id = u.principal_id
WHERE rm.major_id = 0
and u.name not like ''##%''
and u.name not in (''dbo'', ''sa'', ''public'')
ORDER BY rm.permission_name ASC, rm.state_desc ASC
 --Database Level Explicit Permissions
SELECT perm.state_desc
    , perm.permission_name
    ,   QUOTENAME(USER_NAME(obj.schema_id)) + ''.'' + QUOTENAME(obj.name)
       + CASE WHEN cl.column_id IS NULL THEN SPACE(0) ELSE ''('' + QUOTENAME(cl.name COLLATE DATABASE_DEFAULT) + '')'' END AS [Object]
 , QUOTENAME(u.name COLLATE database_default) as Usr_Name
    ,   u.type_Desc
    , obj.type_desc
    ,  TSQL = perm.state_desc + N'' '' + perm.permission_name
  + N'' ON '' + QUOTENAME(USER_NAME(obj.schema_id)) + ''.'' + QUOTENAME(obj.name)
  + N'' TO '' + QUOTENAME(u.name COLLATE database_default)
FROM sys.database_permissions AS perm
 INNER JOIN
 sys.objects AS obj
 ON perm.major_id = obj.[object_id]
 INNER JOIN
 sys.database_principals AS u
 ON perm.grantee_principal_id = u.principal_id
 LEFT JOIN
 sys.columns AS cl
 ON cl.column_id = perm.minor_id AND cl.[object_id] = perm.major_id
where
 obj.name not like ''dt%''
and obj.is_ms_shipped = 0
and u.name not in (''dbo'', ''sa'', ''public'')
ORDER BY perm.permission_name ASC, perm.state_desc ASC
';

HostForLIFE.eu SQL Server 2014 Hosting
HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes. We have customers from around the globe, spread across every continent. We serve the hosting needs of the business and professional, government and nonprofit, entertainment and personal use market segments.



About HostForLIFE.eu

HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes.

We have offered the latest Windows 2016 Hosting, ASP.NET Core 2.2.1 Hosting, ASP.NET MVC 6 Hosting and SQL 2017 Hosting.


Tag cloud

Sign in