.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Problem trying to execute ALTER SCHEMA from code

Posted By:      Posted Date: October 28, 2010    Points: 0   Category :Sql Server

I have a visual basic application which needs to make some changes to a SQL Server database (either SQL Server 2005 or 2008).  Specifically, I am trying to eliminate a schema (e.g. MySchema) from the database altogether.  The first thing I must do is move all database objects from 'MySchema' to 'dbo'.  To that end, I execute the command:

ALTER SCHEMA dbo TRANSFER MySchema.ActionsCompleted

I am using an ODBC connection to the database.  There is a user name and password setup on the server that my application uses for all database access.  The error message I get is:

Cannot find the object 'ActionsCompleted', because it does not exist or you do not have permission.

When I run this exact statement from a query in SQL Server Mgmt Studio, it works fine.  The difference is the user (and therefore the permissions).  When I execute from the SQL Server Mgmt Studio, I am effectively an administrator, from my application, I am not.

So, I am trying to figure out what permissions I need to give my application to execute this line.  The documentation says that the user my have CONTROL priviledges over the securable (in this case the table called MySchema.ActionsCompleted) and ALTER priveledges on the dbo schema.  OK, so next I try the following (in SQL Server MGMT Studio):


View Complete Post

More Related Resource Links

Automatically Execute Code at certain time from website


Is there a way to trigger a piece of code to execute at a certain time once a week?

I basically want my website to send out a reminder email every sunday. I have a function called SendReminder() and I would like to know if it is posible for it to run by itself because at the minute I have to press a button to run it.


What's the problem in my javascript's code to get ClientID Property?



 Hi all.

I wirte a simple java script code to get ClientID of controls on the webform. The code is like:

<script type="text/javascript" language="javascript">

var butt = $find("<%= Button1.ClientID %>");



But when i run it , i have a problem. The probmel is:


Server Error in '/' Application.

The Controls collection cannot be modified because t

Question about user used to execute code from app_code


 Hello. I would like to know something about code execution  in App_Code folder.

Under wich user executed code from app_code.

I'm using impersonate in web.config

How it's possible to execute this code in C # WPF

Hi I have this code but I do not know how to do him in WPF   IF EXISTS (SELECT * FROM YourTable WHERE Key = 123)    PRINT 'EXISTS' ELSE    PRINT 'Dont EXISTS'   There is My Code in c#         private void button2_Click_1(object sender, RoutedEventArgs e)           {             DataSet ds6 = new DataSet();             SqlConnection con6 = new SqlConnection("Data Source=PC;Initial Catalog=Veo;Integrated Security=True");             SqlCommand cmd = new SqlCommand("Select * from [MHGROUP].CUSTOM3", con6);             SqlDataAdapter sqlDa6 = new SqlDataAdapter();             sqlDa6.SelectCommand = cmd;             sqlDa6.Fill(ds6);             string mySelectedValue = comboBox2.Text;             int newid;             newid = Convert.ToInt32(mySelectedValue);  

data contract code generation for large/complex schema (HR-XML/OAGIS) - is there an alternative?

Hello, and thank you for reading.I am implementing a Service based on a predefined specification (HR-XML 3.0). As such, I am starting with the schema, and working my way back to code. There are a number of large Schema documents (which import yet more Schema documents) related to my implementation, provided by this specification.I am able to generate code using xsd.exe, by supplying the "main" and "supporting" xsd files as arguments. But there are several issues, and I am wondering if this is the right approach.- there are litterally hundreds of classes - the code file is half a meg in size- duplicate classes (ex. Type, Type1 - which both represent the same type)- there are classes declared as inheriting from a base class, but that base class is not generated/definedI understand that there are limitations to the types of Schema supported by svcutil.exe/xsd.exe when targeting the DataContractSerializer and even XmlSerializer. My question is two-fold:1. Are code generation "issues" fairly common when dealing with larger, modular xsd files? Has anyone had success with generating data contracts from OAGIS or HR-XML schema?2. Given the above issues, are there better approaches to this task, avoiding generating code and working with concrete objects? Does it make better sence to read and compose a SOAP message directly, while sti

problem with sitemap schema 'xsi:schemaLocation' in XML file creation

SqlConnection conn = new SqlConnection(connStr); conn.Open(); string sql = "select top 10 catnum,cast(case when isnull(onhand,0) < 5 then 0 else round((onhand/2),1) end as int) as onhand from dbo.V_OnHand with (nolock)"; SqlCommand cmd = new SqlCommand(sql, conn); XmlDocument doc = new XmlDocument(); XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", "UTF-8", null); XmlElement rootNode = doc.CreateElement("inventory"); doc.InsertBefore(dec, doc.DocumentElement); rootNode.SetAttribute("xmlns", "http://seller.marketplace.tests.com/inventory/v1"); rootNode.SetAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); rootNode.SetAttribute("xsi:schemaLocation", "http://sellersupport.domain.test.com/test1/s/schema/inventory/inventory-xml-feed-v1.xsd"); doc.AppendChild(rootNode); XmlElement fbm = doc.CreateElement("inventory"); doc.DocumentElement.PrependChild(fbm); SqlDataReader rdr1 = cmd.ExecuteReader(); while (rdr1.Read()) { XmlElement item = doc.CreateElement("item"); item.Set

Problem in downloading a file code.

hey dere, here is my code.....   void transfer() { string filePath = Server.MapPath("~/download"); string _DownloadableProductFileName = "mob.txt"; System.IO.FileInfo FileName = new System.IO.FileInfo(filePath + "\\" + _DownloadableProductFileName); FileStream myFile = new FileStream(filePath + "\\" + _DownloadableProductFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); string lastUpdateTiemStamp = File.GetLastWriteTimeUtc(filePath).ToString("r"); string _EncodedData = HttpUtility.UrlEncode(_DownloadableProductFileName, Encoding.UTF8) + lastUpdateTiemStamp; Response.Clear(); Response.Buffer = false; Response.AddHeader("Accept-Ranges", "bytes"); Response.AppendHeader("ETag", "\"" + _EncodedData + "\""); Response.AppendHeader("Last-Modified", lastUpdateTiemStamp); Response.AddHeader("Content-Disposition", "attachment;filename=" + FileName.Name); Response.End(); Label1.Text = "hel"; } i have two problems in this code.First while running this code i dont get the file damaged or corrupt. Second problem is dat the code exits at Response.End() and doesnt execute d last line... 

execute a javascript function in code page

I use js function in source page and call that js function as below in Source page<a href="javascript:;" onclick="openwin('Sample.aspx?DID=<%#Eval("UID") %>', '', '700','300','yes'); return false ">I need to call this function from vb.net code page.....how to solve this ........???????????Give ur ideas...............

hai i am karthikeyan i have a problem in code

i want to run exe from my application .for that i had pasted my setup in my application . please give solution how to call the exe from my application .......      this is my code-------------------------------------------------------      System.Diagnostics.Process process1 = new System.Diagnostics.Process();         // Set the directory where the file resides         process1.StartInfo.WorkingDirectory = Request.MapPath("C:/Documents and Settings/user9.AIS/My Documents/Visual Studio 2008/WebSites/application/TortoiseSVN-");         // Set the filename name of the file you want to open         process1.StartInfo.FileName = Request.MapPath("TortoiseSVN-");             // Start the process           process1.Start(); -----------------------------------------------------------------   error is this------------------------------------   'C:/Documents and Settings/user9.AIS/My Documents/Visual Studio 2008/WebSites/application/TortoiseSVN-' is not a valid virtual path. &

Namespace problem (code behind "using")

Hello! I downloaded sample code from http://www.asp.net/security/tutorials/validating-user-credentials-against-the-membership-user-store-cs and imported the file "Login.aspx" file into my existing project.  This file has in the code behind the following namespaces: view plaincopy to clipboardprint? using System;   using System.Data;   using System.Configuration;   using System.Collections;   using System.Web;   using System.Web.Security;   using System.Web.UI;   using System.Web.UI.WebControls;   using System.Web.UI.WebControls.WebParts;   using System.Web.UI.HtmlControls;   I added a new page (e.g. Login1.aspx) to my project and copied the above to the top of the code behind page (Login1.aspx.cs).  In the downloaded file from the tutorial (Login.aspx) there is this line of code:Membership.ValidateUser(UserName.Text, Password.Text)And at build everything is OK! But if I add excatly the same code in my newly created page (Login1.aspx.cs) I get the following error: Error 9 The type or namespace name 'ValidateUser' does not exist in the namespace 'Krik.Membership' (are you missing an assembly reference?) G:\Krik\Krik\Login.aspx.cs 27 28 Krik The type or namespace name 'Validat

Looking for sample css code to magnify or alter an image buttons bakground when hovering over them


I have a list of buttons in a menu, and when I hover of them, I want something to change, such as a box being drawn around them, or background color chaning.  How do I do that? 

Problem with EXECUTE AS (SQL 2005)

Hello all,

I am working on setting up a proxy account to use for creating a database snapshot from within a stored procedure in [master].

The login [ProxyTest] has been granted the server roles of [dbcreator] and [public].  The login also has a corresponding user of the same name in [master] which has been granted [db_owner].

The code I am using to create the snapshot is:

(Name = 'MyDBData', Filename = 'E:\MSSQL.3\DATA\MY_SNAPSHOT_MyDB_1.SNAP'),
(Name = 'MyDBData2', Filename = 'E:\MSSQL.3\DATA\MY_SNAPSHOT_MyDB_1_2.SNAP'),
(Name = 'MyDBData3', Filename = 'E:\MSSQL.3\DATA\MY_SNAPSHOT_MyDB_2_3.SNAP'),
(Name = 'MyDBData4', Filename = 'E:\MSSQL.3\DATA\MY_SNAPSHOT_MyDB_3_4.SNAP'),
(Name = 'MyDBData5', Filename = 'E:\MSSQL.3\DATA\MY_SNAPSHOT_MyDB_4_5.SNAP'),
(Name = 'MyDBData6', Filename = 'E:\MSSQL.3\DATA\MY_SNAPSHOT_MyDB_5_6.SNAP'),
(Name = 'MyDBData7', Filename = 'E:\MSSQL.3\DATA\MY_SNAPSHOT_MyDB_6_7.SNAP'),
(Name = 'MyDBData8', Filename = 'E:\MSSQL.3\DATA\MY_SNAPSHOT_MyDB_7_8.SNAP')

The above code works perfectly when logged in as [ProxyTest].

I have put this into the following stored procedure:


error code:0xC0024104 source: Reporting Task for subplan- Description: the execute method on the tas


I am getting following error when running maintenance plan under schedule job. I am getting this error for maintenance cleanup task.  The job is not failing all the time but alternate weeks. I created same maintenance plan on test server(same configuration as PROD) and Maintenance cleanup task related job failed for first time and running fine from there. I don't know why it is causing failed. I checked maintenance plan history and it show successful each time. even i checked manually it deleted all the report files related to maintenance plan. History Cleanup task and Maintenance Cleanup task should not be created on same Maintenance Plan?....I know SQL Server 2005 had some problem with maintenance plan creation before SP2.

i wrote an code in button_click event and i want to execute the same code when i click another butto


Hello all ,

i wrote an code in button_click event and i want to execute the same code when i click another button

how can i do that ?

Kareem Naguib

Problem with Execute SQL Task for XML type of Result Set


Hi All

I am calling SQL Query through Execute SQL Task

SELECT EmployeeID,NationalIDNumber,ContactID

FROM HumanResources.Employee

FOR XML RAW('Facility'),Root('Extract'),Elements 

and assigning the result set (XML) to a variable(Data) of String Datatype. After SQL Task I am using Script Task and  reading variable (Data) and has some C# in it.

StreamWriter outfile = new StreamWriter(@"C:\Output.xml");


when I execute the package, XML file is created but when i open the file, XML is not formed correctly and I am getting error 

" End element was missing the character '>'. Error processing resource 'file "

But the same query was successful when i run in SSMS


Please help me.

Thanks in Advance

Need to execute ALTER DATABASE inside stored procedure


SQL 2005 Standard.

I wrote a sp that uses ALTER DATABASE instruction. When I execute sp with elevated user it works fine; when I try to execute that sp with a normal user (I alerady gave execute permission for that user) it fails with "alter database failed".

I tried to modify create proc with execute as owner but nothing changed.

How can I do ?


VS2010 - Problem with WinForms generated code



I'm having trouble with the code that is generated automatically by the WinForms designer, sometimes it generates code that uses the 'components' (IContainer) in the constructors of disposable components and other times it doesn't.

Here is some code. First the code that is generated in a clean new project with just one component on the form:

  private void InitializeComponent()
   this.components = new System.ComponentModel.Container();
   this.errorProvider1 = new System.Windows.Forms.ErrorProvider(this.components);
   // errorProvider1
   this.errorProvider1.ContainerControl = this;
   // Form1
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend