i am using visual web developer 2005 and SQL Express 2005 and VB as the code behindi have a table called orderdetail and i want to update the fromdesignstatus field from 0 to 1 in one of the rows containing order_id = 2so i am using the following coding in button click event Protected Sub updatebutton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Dim update As New SqlDataSource() update.ConnectionString = ConfigurationManager.ConnectionStrings("DatabaseConnectionString").ToString() update.UpdateCommandType = SqlDataSourceCommandType.Text update.UpdateCommand = "UPDATE orderdetail SET fromdesignstatus = '1' WHERE order_id = '2'" End Sub but the field is not updatedi do not know where i have gone wrong in my coding. i am sure that my database connection string is correctplease help me
hi, i am tryuing to use the gridview as means for the user to be able to edit delete and update columns of the database. however when it is run in the browser it allows the user to edit the fields but when i click on the update button it throws an error. can someone please offer me advice on how i can sort this problem out or provide me with any examples as i cant see what the error is. i used the option in edit columns which allows you to specify you want update delete etc controls added to the gridview. how can i make it so it supports updating? thank you Updating is not supported by data source 'SqlDataSource1' unless UpdateCommand is specified. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NotSupportedException: Updating is not supported by data source 'SqlDataSource1' unless UpdateCommand is specified.Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Hey people im just wondering if someone could help me out with this Insert query im doing from one of the learn asp videos. I have a table called EquipmentBooking and it contains the following fields <teachingSession, int,> <staff, char(5),> <equipment, varchar(15),> <bookedOn, datetime,> <bookedFor, datetime,> now im doing the following Insert statement in Visual Studio 2005 when the submit button is clicked but all I get is the catched error exception and I just can working out why. Can someone help? heres the code im using Dim WebTimetableDataSource As New SqlDataSource()WebTimetableDataSource.ConnectionString = ConfigurationManager.ConnectionStrings("WebTimetableConnectionString").ToString() WebTimetableDataSource.InsertCommandType = SqlDataSourceCommandType.Text WebTimetableDataSource.InsertCommand = "INSERT INTO EquipmentBooking (teachingSession, staff, equipment, bookedOn, bookedFor) VALUES (@TeachingDropDown, @StaffDropDown, @EquipmentDropDown, @DateTimeStamp, @DateTextBox)"WebTimetableDataSource.InsertParameters.Add("TeachingDropDown", TeachingDropDown.Text) WebTimetableDataSource.InsertParameters.Add("StaffDropDown", StaffDropDown.Text)WebTimetableDataSource.InsertParameters.Add("EquipmentDropDown", EquipmentDropDown.Text) WebTimetableDataSource.InsertParameters.Add("DateTimeStamp", DateTime.Now())WebTimetableDataSource.InsertParameters.Add("DateTextBox", DateTime.Now()) Dim rowsAffected As Integer = 0 Try rowsAffected = WebTimetableDataSource.Insert()Catch ex As Exception Server.Transfer("problem.aspx") Finally WebTimetableDataSource = Nothing End Try If rowsAffected <> 1 ThenServer.Transfer("confirmation.aspx") End If
This is a real head ache. Nothing I do to add a record to my SQL2k Database wil work.
I'm logged into it as "sa".
I've Tried Stored Procedures:
Dim myConnection As New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString")) Dim myCommand As New SqlCommand("AddLender", myConnection) ' Mark the Command as a SPROC myCommand.CommandType = CommandType.StoredProcedure
Dim parameterUserName As New SqlParameter("@UserName", SqlDbType.NVarChar, 100) parameterUserName.Value = userName myCommand.Parameters.Add(parameterUserName)
Dim parameterName As New SqlParameter("@Name", SqlDbType.NVarChar, 100) parameterName.Value = name myCommand.Parameters.Add(parameterName)
Dim parameterCompany As New SqlParameter("@Company", SqlDbType.NVarChar, 100) parameterCompany.Value = Company myCommand.Parameters.Add(parameterCompany)
Dim parameterEmail As New SqlParameter("@Email", SqlDbType.NVarChar, 100) parameterEmail.Value = email myCommand.Parameters.Add(parameterEmail)
Dim parameterContact As New SqlParameter("@Contact", SqlDbType.NVarChar, 100) parameterContact.Value = contact myCommand.Parameters.Add(parameterContact)
Dim parameterPhone As New SqlParameter("@Phone", SqlDbType.NVarChar, 100) parameterPhone.Value = Phone myCommand.Parameters.Add(parameterPhone)
Dim parameterFax As New SqlParameter("@Fax", SqlDbType.NVarChar, 100) parameterFax.Value = Fax myCommand.Parameters.Add(parameterFax)
CREATE PROCEDURE AddLender ( @Username nvarchar(100), @ModuleID int, @Email nvarchar(100), @Name nvarchar(100), @Rep nvarchar(250), @Phone nvarchar(250), @Fax nvarchar(250), @City nvarchar (100), @State nvarchar(100), @ItemID int OUTPUT ) AS INSERT INTO Lenders ( Email, Name, Rep, Phone, Fax, CIty, State ) VALUES ( @Email, @Name, @Rep, @Phone, @Fax, @City, @state
) SELECT @ItemID = @@Identity
GO
I get no Errors... I've run SQLProfiller and I don;t even see it run...
I also tried the method..
Dim strSql As String Dim objDataSet As New DataSet() Dim objConnection As OleDbConnection Dim objAdapter As OleDbDataAdapter
strSql = "Select ItemId,ModuleId,Name,Rep, Email,Phone,Fax,City,State,Address From Portal_Lenders;"
objConnection = New OleDbConnection(ConfigurationSettings.AppSettings("ConnectionStringOledb")) objAdapter = New OleDbDataAdapter(strSql, objConnection)
objAdapter.Fill(objDataSet, "Lenders")
Dim objtable As DataTable Dim objNewRow As DataRow
SET IDENTITY_INSERT table name ON I use this to run it:
Code Snippet
.
.
.
Dim command As SqlCommand = New SqlCommand("SET IDENTITY_INSERT table name ON", msSqlConexion) command.ExecuteNonQuery() It doesn't throw any kind of errors, but it actually don't execute it, and If I run it on console it works ok.
My compiler says that the line in bold below is illegal. The error msg I'm getting is: No overload for method 'select' takes '0' arguments. How can I correct this error and execute a SELECT? protected void Button1_Click(object sender, EventArgs e) { SqlDataSource2.Select (); } protected void SqlDataSource2_Selected(object sender, SqlDataSourceStatusEventArgs e) {string strReadyFirstName = e.Command.Parameters["@FirstName"].Value.ToString();string strReadyLastName = e.Command.Parameters["@LastName"].Value.ToString(); } <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT [User_ID], [User_Name], [FirstName], [LastName], [Company_Name], [Department_Name] FROM [CompanyDepartment] WHERE ([User_Name] = @User_Name)" OnSelected="SqlDataSource2_Selected"> <selectparameters> <asp:sessionparameter DefaultValue="TheirUserName" Name="User_Name" SessionField="TheirUserName" Type="String" /> </selectparameters> </asp:SqlDataSource>
Hi :eek: I have a strange problem on my sql 2000 sp4 server
When I kill a session I gives me
Msg 6101, Level 16, State 1, Line 2 Process ID 61 is not a valid process ID. Choose a number between 1 and 32817.
The process exists in sp_who and sp_who2 it even has an entry in the sysprocesses this happens with all processes even test ones that we create that are'nt doing anything
any suggections (I have been told to re-install sql 2000 but this is not possible as it is a production server and I will only get maintenance time on sunday's not enough time to rebuild )
Hi there, I'm not exactly sure where to post this question, so I'll post it here.
I have 2 Windows XP machines, not part of a network domain. One of the XP machines is running SQL Server 2005 Express edition, lets call this DB machine. The other machine is just running my application - App machine. As part of my application, I want to be able to do a backup of the database.
The DB machine is also running the application. If I log into my application on the DB machine using SQL Server Authentication, and run the backup it works fine. (It's using the T-SQL BACKUP command). If it log into my application on the App machine, and try to do the backup, I'm getting an error saying that "The user is not associated with a trusted SQL connection". The same user is being used in both scenarios, and this user can update the database fine on the App machine, so it's not really a connection problem, it seems a permission problem. The SQL user I have created is a member of the db_backupoperator role for the required database.
Is anyone aware as to why I would be getting this error?
Hello,The PRINT command works fine on Query Analyzer.However, when I used it with other Database Client,eg: Aqua Data Studio, nothing got printed out.Is there a way to make it work?Thanks in advance.
Hi there, I'm not exactly sure where to post this question, so I'll post it here.
I have 2 Windows XP machines, not part of a network domain. One of the XP machines is running SQL Server 2005 Express edition, lets call this DB machine. The other machine is just running my application - App machine. As part of my application, I want to be able to do a backup of the database.
The DB machine is also running the application. If I log into my application on the DB machine using SQL Server Authentication, and run the backup it works fine. (It's using the T-SQL BACKUP command). If it log into my application on the App machine, and try to do the backup, I'm getting an error saying that "The user is not associated with a trusted SQL connection". The same user is being used in both scenarios, and this user can update the database fine on the App machine, so it's not really a connection problem, it seems a permission problem. The SQL user I have created is a member of the db_backupoperator role for the required database.
Is anyone aware as to why I would be getting this error?
I have a script from ASP.NET application services. It can be crated using the aspnet_regsql.exe utility in the 2.0 framework. The beginning of the script contains the following:
SET @dboptions = N'/**/' SET @dbname = N'databasename'
IF (NOT EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE name = @dbname)) BEGIN PRINT 'Creating the ' + @dbname + ' database...' DECLARE @cmd nvarchar(500) SET @cmd = 'CREATE DATABASE [' + @dbname + '] ' + @dboptions EXEC(@cmd) END GO
USE [databasename] GO I have a database in the App_Data folder in an ASP.NET website project. It shows up in the Server Explorer. But when I run this script on that database, the output seems fine (No rows affected. (0 row(s) returned) etc) but no tables are actually created in the database I ran it on. The database connection string in the Server Explorer has AttachDbFilename and User Instance=True.
So what exactly happens when SQL Server Express executes the CREATE DATABASE and USE [databasename] in this context? Is it ignored, is there now a new database somewhere on my machine, because the script seems to run fine on SOME database, just not the one expected.
I am hosting my website with a web hosting company on the web. My web application readsdata from a SQL server 2005 database. So far I have been able to establish a connection to the database, but when I attempt to query data from a table, I a get an error message.I can't figure out what I am doing wrong here.basically I just want to read data from acolumn in the database and to store it into a multi-line textbox control. I am using someinline sql for the call. Can someone help me out here? public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { mySqlConnection = new SqlConnection(ConnectionStringConst); mySqlConnection.Open(); try { // Database is named "Torsion", Table I am querying is named "Content" SqlCommand cmd = new SqlCommand("SELECT * FROM [Torsion].[dbo].[Content] ORDER BY [Section] DESC", mySqlConnection); rdr = cmd.ExecuteReader(); ListBox1.DataSource = rdr[0]; ListBox1.DataTextField = "HLContent"; // HLContent is the first column in my database ListBox1.DataBind(); // I want to store HLContent into ListBox1 control } catch { throw;} finally { mySqlConnection.Close(); mySqlConnection.Dispose(); } }}-----------------------------------------ERROR_MESSAGE_BELOW---------------------------- Server Error in '/' Application.
Invalid attempt to read when no data is present. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidOperationException: Invalid attempt to read when no data is present.Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace:
[InvalidOperationException: Invalid attempt to read when no data is present.] System.Data.SqlClient.SqlDataReader.GetValue(Int32 i) +137 System.Data.SqlClient.SqlDataReader.get_Item(Int32 i) +7 _Default.Button1_Click(Object sender, EventArgs e) +167 System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102
Version Information: Microsoft .NET Framework Version:2.0.50727.832; ASP.NET Version:2.0.50727.832
I have a little application that I have designed where I need to be able to execute create table and create function comands against the database. It seems that it does not like my sql file. Does anyone know of a different method of doing this?
Error message Line 2: Incorrect syntax near 'GO'. Line 4: Incorrect syntax near 'GO'. Line 8: Incorrect syntax near 'GO'. 'CREATE FUNCTION' must be the first statement in a query batch. Must declare the variable '@usb'. Must declare the variable '@usb'. Must declare the variable '@i'. A RETURN statement with a return value cannot be used in this context. Line 89: Incorrect syntax near 'GO'. Line 91: Incorrect syntax near 'GO'. Line 94: Incorrect syntax near 'GO'.
Protected Sub Install() Dim err As String = "" While err.Length < 1 ' Dim your StreamReader Dim TextFileStream As System.IO.TextReader 'Load the textfile into the stream TextFileStream = System.IO.File.OpenText(Request.PhysicalApplicationPath & "Scripts .sql") 'Read to the end of the file into a String variable. executesql(TextFileStream.ReadToEnd, err)
err = "Susscessful" End While If err = "Susscessful" Then Response.Redirect("Default.aspx") Else Me.lblError.Text = err End If End Sub Private Function executesql(ByVal s As String, ByRef err As String) As Boolean Try Dim conn As New Data.SqlClient.SqlConnection(GenConString()) Dim cmd As New Data.SqlClient.SqlCommand(s, conn) conn.Open() cmd.ExecuteNonQuery() conn.Close() Return True Catch ex As Exception err = ex.Message.ToString Return False End Try End Function
Example sql file SET QUOTED_IDENTIFIER ON GO SET ANSI_NULLS ON GO if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[MyFunc]') and xtype in (N'FN', N'IF', N'TF')) drop function [dbo].[MyFunc] GO CREATE FUNCTION [dbo].[MyFunc] ( -- Add the parameters for the function here
) RETURNS varchar(1000) AS BEGIN -- Declare the return variable here DECLARE @Result varchar(1000) -- Add the T-SQL statements to compute the return value here -- Do something here -- Return the result of the function RETURN @Result END GO SET QUOTED_IDENTIFIER OFF GO SET ANSI_NULLS ON GO
In SQL Server using xp_cmdshell we can excute any of the command or executable files which can be executed in command prompt. Here my problem is that .. I am trying to execute OSQL from the MSSQL(Query Analyser) using xp_cmdshell.. but its give error saying "'osql' is not recognized as an internal or external command, operable program or batch file." This error occours when it is not able to find the executable file... but same thing I am able to execute from the command prompt. So I feel this problem is some where related to the path setting of windows. If some one can solve this problem or sugesst the how to set the path for window it will be help full.. waiting for reply
I wanted to know if there is a way to execute sql commands on the operating system's command line. If it is possible, then how do we do it ? For example to execute a SELECT * from Table statement what are we supposed to do ?
Hi, I need to execute some store procedures I have in the SQL editor but I seem to been having problems with the formatting for datetime variables needed for the execution of my code. can anyone please help? thanks in Advance
THE STORED PROCEDURE SAMPLE ALTER PROCEDURE [dbo].[usp_CMSTemplateCreateNewTemplate] @SiteID AS INT, @PageID AS INT, @Title AS NVARCHAR(50), @EditHREF AS NVARCHAR(512), @CreatorID AS INT, @StartDate AS DATETIME, @EndDate AS DATETIME, @Child AS INT,@PageTemplateID AS INT OUTPUT AS
I'm wondering if there is any way for me to execute any type of command (delete, insert, create, alter, etc) on management studio without having to wait the server answer.
On Oracle, I use DBMS_JOB. On SQL Server, do I have to create a SQL SERVER Agent Job? What if I don't have permission to create that kind of jobs?
Hello, the following code works perfectly in SQL Server 2000 and SQL Server 2005 Express over WinXP but when run against an instance of SL Server2005 Express over Win2003Server, the first time Command.Execute is invoked returns no error (even though no action seems to be take by the server), subsequent calls return the error -2147217900 couldn't find prepared instruction with identifer -1 (message may vary, it is a translation from may locale)
Any ideas? Thanks
Code Block Public Sub Insert_Alarm(sIP As String, nAlarm As Long) Static cmdInsert As ADODB.Command Static Initialized As Boolean On Error GoTo ErrorHndl If Not Initialized Then Set cmdInsert = New ADODB.Command Set cmdInsert.ActiveConnection = db cmdInsert.Parameters.Append cmdInsert.CreateParameter("IP", adVarChar, adParamInput, Len(sIP), sIP) cmdInsert.Parameters.Append cmdInsert.CreateParameter("Alarm", adInteger, adParamInput, , nAlarm) cmdInsert.CommandText = "insert into ALARMS(date_time,ip,alarm,status) values (getdate(),?,?,1)" cmdInsert.CommandType = adCmdText cmdInsert.Prepared = True Initialized = True End If cmdInsert.Parameters(0).value = sIP cmdInsert.Parameters(1).value = nAlarm cmdInsert.Execute Exit Sub ErrorHndl: ... End Sub
Hi! I try to find out how to write an tsql program that sends dmx-ddl to SSAS. this works: select * from openquery(bdjOLAP, 'select <col> from <modelname>.content') because it returns an resultset.
but how to something similar this (would fail, because no result set is returned): select * from openquery(bdjOLAP, 'create mining structure...')
We have an ASP 3.0 application that currently works "correctly" on one server, Server A, and we€™re testing it on another server, Server B, which is 64 bit.
For this example, the stored procedure sp_TestProcedure is:
CREATE PROCEDURE sp_TestProcedure @Name varchar(50) AS INSERT INTO tblTest ([Name], Date) VALUES (@Name, getDate()) SELECT COUNT(*) AS 'Count' FROM tblTest
The basic point is the stored procedure does an INSERT and then a SELECT.
Now... to the issue. On Server A, the variable rs above ends up with a single open Recordset which is the results of the SELECT statement. However, on Server B, rs is set to a closed recordset, and rs.NextRecordset() gets a second recordset of the results of the SELECT statement.
I understand what's going on. Server B is first returning the number of rows affected by the INSERT which translates to a closed recordset. But Server A does not do this.
I would like to know why the default behavior of the command's .Execute is different on the different servers. Does it relate to the Provider/Driver settings in the connection string? Does it have anything to do with 64 bit VS. 32 bit servers?
I know that one way to address this issue to add SET NOCOUNT ON to the start of the stored procedure. But we have many stored procedures, and if the solution is a change in the connection string, that would be preferred. Also, whatever the possible solution is, I also looking to discover *why* it's happening.
I am trying to push the install for ReportBuilder 3.0 and am having an issue with the REPORTSERVERURL option for installing via command line.I have a batch file that works fine, however when I launch the app it does not have a report server configured. I have verified I can connect to my report server if I enter it manually.
Hi everybody, I would like to know if it's possible to execute a stored procedure, passing it parameters, using not CommandType.StoredProcedure value of sqlcommand, but CommandType.Text.
I tried to use this: sqlCmd.CommandType = CommandType.Text sqlCmd.Parameters.Add(sqlPar) sqlCmd.ExecuteNonQuery()
With this sql command: "exec sp ..."
I wasn't able to make it to work, and I don't know if it's possible.
Another question: if it's not possible, how can I pass a Null value to stored procedure? This code: sqlPar = new SqlParameter("@id", SqlDbType.Int) sqlPar.Direction = ParameterDirection.Output cmd.Parameters.Add(sqlPar)
sqlPar = new SqlParameter("@parent_id", DBNull) cmd.Parameters.Add(sqlPar)
doesn't work, 'cause I get this error: BC30684: 'DBNull' is a type and cannot be used as an expression.
How can I solve this? Bye and thanks in advance.
P.S. I would prefer first method to call a stored procedure ('cause I could call it with 'exec sp null' sql command, solving the other problem), but obviusly if it's possible...=)
Hi, I need to send a table data into flat and then ftp into different location. I was using xp_cmdshell via sql task but my network engineer is saying that this xp_cmdshell will break the security and recomond to use "Execute Process Task". If i'm using this task getting the below error. Could you advice me regrding network engineer thought and any solution for avoiding this error.
--------------------------- Execute Process Task: C:WINDOWSsystem32ftp.exe --------------------------- CreateProcessTask 'DTSTask_DTSCreateProcessTask_1': Process returned code 2, which does not match the specified SuccessReturnCode of 0. --------------------------- Thanks,
Hi, I'm looking into the idea of building an enhanced version of dtexec.exe that builds in some extra logging features. My utility will execute packages using the Package.Execute() method.
Thing is, I'd still want to support all of the command-line options that dtexec supports. For example, my utility should accept "/set package.variables[myvariable].Value;myvalue" and pass it through to the executing package but I can't find a way of doing it using Package.Execute().
Am I missing something or is this just not possible?