Translate

SQL server attach a series of database using query

Wednesday, February 19, 2014 Category : 0

1 . step one
save all attach database name of you pc sql server using following command.

SELECT * FROM sys.master_files

Save the result to excel sheet.

now if you re-install your pc OS.


use the following. query for resotre all database. you may need some tuning to your database depend on the data found.




declare @dbName nvarchar(max)
declare @dbpath nvarchar(max)

declare dbc cursor for


-- Note F1 condition is used for escap some database . no need to attach those db
-- Note F2 condition is used to load only mdf file

select db_name,path from tablesm where F1>9 and F2=1


open dbc

fetch next from dbc into @dbName,@dbpath

while @@fetch_status = 0

begin

declare @logs nvarchar(max)

-- Note generating log file location from mdf file.
set @logs = substring(@dbpath,0,len(@dbpath)-3) + '.LDF'
--print @logs

declare @SQL  nvarchar(max)

set @SQL ='
CREATE DATABASE '+@dbName+'
 ON
( FILENAME = '''+@dbpath+''' ),
( FILENAME = '''+@logs+''' )
 FOR ATTACH
 '
--print @SQL
exec( @SQL)

fetch next from dbc into @dbName,@dbpath

end

close dbc
deallocate dbc

Microsoft sql server error : 5123 [Solved]

Category : 0

Access denied Error Solution :

open the properties of ldf and mdf file
1.  Check the owner ship status of mdf and ldf file.
2. Check if there a use call  Everyone user added to file group , if not found then added it to and give full permission.










1. if you have a lot file to do this operation you can do it using command prompt.


for taking ownership of all database or file of a directorry

D:
cd D:\SOL ServerDatabase2008\All
pause
takeown /f . /r
pause

save it and give extension of bat file and then execute using admin previlage


for add everyone user of a direcotry

icacls * /t  /grant Everyone:F
pause

must run on same directory




Unable to load one or more of the requested types. (C#)

Thursday, January 16, 2014 Category : 0

System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.

Error was found : when we are developing an application using .net framework 4, on visual 2010, using entity framework, it works perfectly on local or devlopement pc.

but in clinet side it's not working. and give the above error. after trying lot of things we are able to discover soltion
if we change the reference properties behavious which we use in our project. it work

so the solution is

select the follwoing references 


  • System.Data.Entity
  • System.Web.Entity
and change the property of copy local to True. build the solution now, and now you will get those reference dll in your bin. and now problem will solve.

System.ComponentModel.Win32Exception: Access is denied Error [Solved]

Wednesday, January 15, 2014 Category : 0

IIS ExternalException (0x80004005): Cannot execute a program. The command being executed was "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe 

Solution : Go to your application app pool . open advance settings. focus on Identity and then set your administrator privilege account. then restart app pool. and visit it again.


Sys.Extended is undefined (AjaxControlToolkit asp.net)

Tuesday, November 5, 2013 Category : 2

if u get this type 'Sys.Extended is undefined ' error in asp.net AjaxControlToolkit latest version on (4.1.7.1005)

use Ajaxtoolkit script manager not <asp:ScriptManager>

  <ajaxToolkit:ToolkitScriptManager EnablePartialRendering="true" runat="Server" ID="ScriptManager1" />




ASP.NET open a new window with asynchronous post back

Monday, September 30, 2013 Category : 0

asp.net open a new window using java


[Serializable]
    public class Result : System.Web.UI.Page
    {

public void showReportModified(string pageUrl, string param, Type cType, Page oPage,Control ctrl)
        {
 ScriptManager.RegisterStartupScript(ctrl, typeof(string), "redirect", "window.open('" + url + "');", true);
}

}


in your web page c# code where you open to a new window

protected void btnSave_Click(object sender, EventArgs e)
    {
new Result().showReportModified("url", "parameter" , this.GetType(), this.Page, UpdatePanel1);
}

ASP.NET MVC 4 , Ajax Image Upload

Sunday, August 25, 2013 Category : 1

<tr>
                    <th>
                        @Html.LabelFor(m => m.NewsBody)
                    </th>
                     <td>
                        @Html.TextAreaFor(m => m.NewsBody, new { @class = "my-textBox" })
                        @Html.ValidationMessageFor(m => m.NewsBody)
                    </td>
                </tr>


<script type="text/javascript">

    // Call this function on upload button click after user has selected the file
    function UploadFile() {
        var file = document.getElementById('etlfileToUpload').files[0];
        if(file == null) {return;}
        var fileName = file.name;
        var fd = new FormData();
        fd.append("fileData", file);
        var xhr = new XMLHttpRequest();
        xhr.upload.addEventListener("progress", function (evt) { UploadProgress(evt); }, false);
        xhr.addEventListener("load", function (evt) { UploadComplete(evt); }, false);
        xhr.addEventListener("error", function (evt) { UploadFailed(evt); }, false);
        xhr.addEventListener("abort", function (evt) { UploadCanceled(evt); }, false);
        xhr.open("POST", "/AP/FileUpload", true);
        xhr.send(fd);
    }


    function UploadProgress(evt) {
        if (evt.lengthComputable) {
            var percentComplete = Math.round(evt.loaded * 100 / evt.total);
            $("#uploading").text(percentComplete + "% ");
        }
    }

    function UploadComplete(evt) {
        if (evt.target.status == 200){
            //alert(evt.target.responseText);
            $("#uploading").text("Upload Success");
            $(".path").text(evt.target.responseText);
            document.getElementById('etlfileToUpload').parentNode.innerHTML = document.getElementById('etlfileToUpload').parentNode.innerHTML;

            }
        else {
            $("#uploading").text("Error Uploading File");
            //alert("Error Uploading File");
        }
    }

    function UploadFailed(evt) {
        alert("There was an error attempting to upload the file.");
    }

    function UploadCanceled(evt) {
        alert("The upload has been canceled by the user or the browser dropped the connection.");
    }

</script>






 [HttpPost]
        public JsonResult FileUpload(HttpPostedFileBase fileData)
        {
            string path = "";
            if (fileData != null)
            {
                string pic = System.IO.Path.GetFileName(fileData.FileName);
                path = System.IO.Path.Combine(Server.MapPath("~/news.resource"), pic);
                // file is uploaded
                fileData.SaveAs(path);
                path = pic;
                // save the image path path to the database or you can send image directly to database
                // in-case if you want to store byte[] ie. for DB
                /*using (MemoryStream ms = new MemoryStream())
                {
                    fileData.InputStream.CopyTo(ms);
                    byte[] array = ms.GetBuffer();
                }*/

            }
            // after successfully uploading redirect the user
            return Json(path);
            //return RedirectToAction("actionname", "controller name");
        }

Powered by Blogger.