Showing posts with label code. Show all posts
Showing posts with label code. Show all posts

Monday, March 26, 2012

install MSDE200A

Hi can you help me with this problem with msde
I have installed MSDE200A and i didn’t gave any password(setup BLANKSAPWD=1).
My configuration code for the connection with msde is:
<appSettings>
<add key="DSN" value="Initial Catalog=dyt_mac;Data
Source=localhost;Integrated Security=SSPI;"/>
</appSettings>
When i try to connect with the database this error occurs:
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.Data.SqlClient.SqlException: SQL Server does not
exist or access denied.
Thank you!
Hi,
the DataSource value should be '(local)' including the brackets.

Wednesday, March 21, 2012

Install Err 1603

Hi,
I have attempted to install the Reporting Services v1 onto my development
machine with no luck. I get an error "SetupDialog, Error Code 1603". I
have searched for all occurances of this message and followed the information
that I have been able to find.
The strange thing is that I am following the same installation process that
I did with my original w2k dev box, yet it did not have any issuses during
the install.
My dev box is a Windows XP Sp2 with SQL Server Developer installed and using
VS.Net 2003.
So what am I doing wrong?
--
Frank BradleyPlease read this knowledge Base Article for your problem-
http://support.microsoft.com/?kbid=867872
-Suneet Mohan
"Frank Bradley" wrote:
> Hi,
> I have attempted to install the Reporting Services v1 onto my development
> machine with no luck. I get an error "SetupDialog, Error Code 1603". I
> have searched for all occurances of this message and followed the information
> that I have been able to find.
> The strange thing is that I am following the same installation process that
> I did with my original w2k dev box, yet it did not have any issuses during
> the install.
> My dev box is a Windows XP Sp2 with SQL Server Developer installed and using
> VS.Net 2003.
> So what am I doing wrong?
>
> --
> Frank Bradley|||As I stated in my post the first thing I always do is search the knowledge
base for a solution and that specufic article I read a nuber of time with no
solution.
When I get the error screen that appear, just after the check for the
required components, the screen displays the error and the only choices I
have to select is Help or Cancel.
Frank
"Suneet" wrote:
> Please read this knowledge Base Article for your problem-
> http://support.microsoft.com/?kbid=867872
>
> -Suneet Mohan
> "Frank Bradley" wrote:
> > Hi,
> >
> > I have attempted to install the Reporting Services v1 onto my development
> > machine with no luck. I get an error "SetupDialog, Error Code 1603". I
> > have searched for all occurances of this message and followed the information
> > that I have been able to find.
> >
> > The strange thing is that I am following the same installation process that
> > I did with my original w2k dev box, yet it did not have any issuses during
> > the install.
> >
> > My dev box is a Windows XP Sp2 with SQL Server Developer installed and using
> > VS.Net 2003.
> >
> > So what am I doing wrong?
> >
> >
> > --
> > Frank Bradley|||I had the same error/situation and this got me going-
(this assumes Windows is installed on your C: drive)
1) Navigate to C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322
2) Open a command prompt and run this (without the quotes): "aspnet_regiis -c"
The RS installation should now work; it did for me.
Good luck!
Cheers,
dj
"Frank Bradley" wrote:
> As I stated in my post the first thing I always do is search the knowledge
> base for a solution and that specufic article I read a nuber of time with no
> solution.
> When I get the error screen that appear, just after the check for the
> required components, the screen displays the error and the only choices I
> have to select is Help or Cancel.
>
> Frank
> "Suneet" wrote:
> > Please read this knowledge Base Article for your problem-
> > http://support.microsoft.com/?kbid=867872
> >
> >
> > -Suneet Mohan
> >
> > "Frank Bradley" wrote:
> >
> > > Hi,
> > >
> > > I have attempted to install the Reporting Services v1 onto my development
> > > machine with no luck. I get an error "SetupDialog, Error Code 1603". I
> > > have searched for all occurances of this message and followed the information
> > > that I have been able to find.
> > >
> > > The strange thing is that I am following the same installation process that
> > > I did with my original w2k dev box, yet it did not have any issuses during
> > > the install.
> > >
> > > My dev box is a Windows XP Sp2 with SQL Server Developer installed and using
> > > VS.Net 2003.
> > >
> > > So what am I doing wrong?
> > >
> > >
> > > --
> > > Frank Bradley

Friday, March 9, 2012

Insertparameters in code-behind

Hi,

How do I use insertparameters in code-behind? This is the code that I have

Dim insertSqlAs StringinsertSql ="INSERT INTO [xyzTable] ([x], [y]) VALUES (@.x, @.y)"SqlDataSource1.InsertCommand = insertSqlSqlDataSource1.InsertParameters.Add("@.x","124")SqlDataSource1.InsertParameters.Add("@.y","456")SqlDataSource1.Insert()

When I execute these line of code I get an error saying

"Must declare the variable '@.x'."

Please help

I assume your code block is under button click event:

Protected Sub Button1_Click(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles Button1.Click

Dim insertSqlAs String
insertSql ="INSERT INTO [xyzTable] ([x], [y]) VALUES (@.x, @.y)"
SqlDataSource1.InsertCommand = insertSql
SqlDataSource1.InsertParameters.Add("x","124")
SqlDataSource1.InsertParameters.Add("y","456")
SqlDataSource1.Insert()

End Sub

ADO.NET parameter and ASP.NET parameter are different. ADO.NET parameters always start with @. sign.

|||That simple -- just remove the @. sign. Thanks for your help

InsertParameters for SqlDataSource

Hello, I have a SqlDataSource named "OrderHistoryDataSource" that I want to add a parameter to from the code behind file. THe reason I want to do this is todynamicly add the UserID from a currently logged on user. What am I doing wrong? Is there a better way?My code below:

---------------------Code behind file-----------------------

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;public partialclass OrderHistory : System.Web.UI.Page{protected void Page_Load(object sender, EventArgs e) {//If the user is not logged in this will redirect to Login.aspxif (!Request.IsAuthenticated) { Response.Redirect("~/Login.aspx"); }//test to display userID MembershipUser myObject = Membership.GetUser();string UserGUID = myObject.ProviderUserKey.ToString(); SqlDataSource DataSource = Page.FindControl("OrderHistoryDataSource"); DataSource.InsertParameters.Add("CurrentUserId", UserGUID.ToString()); DataSource.Select(); }}

---------------------Asp.netfile-----------------------

<%@. Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="OrderHistory.aspx.cs" Inherits="OrderHistory" Title="Untitled Page" %><asp:Content ID="Content1" ContentPlaceHolderID="CONTENT" Runat="Server"> <table id="ContentTable"> <tr> <td id="ContentTitleCell" colspan="3" style="width: 684px"> ORDER HISTORY</td> </tr> <tr> <td colspan="3" rowspan="2" style="width: 684px"> <asp:GridView ID="OrderHistoryGrid" runat="server"> </asp:GridView>   <asp:SqlDataSource ID="OrderHistoryDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString%>" SelectCommand="SELECT * FROM [UserOrders] WHERE ([UserID] = [CurrentUserID]) ORDER BY [OrderID] VALUES (@.UserId, @.Address, @.City, @.State, @.Zip)" ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName%>"> <InsertParameters></InsertParameters> </asp:SqlDataSource> </td> </tr> <tr> </tr> </table></asp:Content>

Hello,

By looking in the code that you have given, I can definitely say there is some thing wrong. Please check youe code again.

You can follow the code below.

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="UserID" HeaderText="UserID" SortExpression="UserID" />
<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
<asp:BoundField DataField="FirstName" HeaderText="FirstName" SortExpression="FirstName" />
<asp:BoundField DataField="MiddleName" HeaderText="MiddleName" SortExpression="MiddleName" />
<asp:BoundField DataField="LastName" HeaderText="LastName" SortExpression="LastName" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="OrderHistoryDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [UserID], [Title], [FirstName], [MiddleName], [LastName] FROM [UserOrders] WHERE ([UserID] = @.UserID)">
<SelectParameters>
<asp:Parameter Name="UserID" Type="String" />
</SelectParameters>
</asp:SqlDataSource>

---------------------Codebehindfile-----------------------

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;

public partialclass OrderHistory : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//If the user is not logged in this will redirect to Login.aspx
if (!Request.IsAuthenticated)
{
Response.Redirect("~/Login.aspx");
}

//test to display userID
MembershipUser myObject = Membership.GetUser();
string UserGUID = myObject.ProviderUserKey.ToString();
OrderHistoryDataSource.SelectParameters["UserID"].DefaultValue = UserGUID;
GridView1.DataBind();
}
}

Thanks,

Deepesh Verma


|||

Thank you very much. I figured I had the general idea; I was just off by a bit.

|||

I would typically suggest moving the code to the SqlDatasource_Selecting event. Within that event, you can set any parameters you want through the e.Command property. It also will get executed each time a select will fire, and only when a select will fire.

Insertion With Explicit IDENTITY

Hi,
I'm writing a database interface to someone else's code and am getting passed INSERT statements that look something like this:

INSERT INTO my_table(my_id, my_val)
VALUES (%s, 5)

My code is expected to replace the %s with a suitable value for an ID. Now, my_table looks like this:

CREATE TABLE my_table (
my_id INT IDENTITY(1,1) PRIMARY KEY,
my_val INT
)

and I'm trying to get a suitable value for the '%s' such that the insert will work correctly. I understand that I need to 'SET IDENTITY_INSERT my_table ON' prior to the insert, but what can I replace '%s' with? I can't put a separate SELECT statement in there, and @.@.IDENTITY is too global to be useful (it's a multithreaded app with a lot of inserts across multiple tables). Hacking the input string to remove the 'my_id, ' and '%s, ' completely is not allowed (unfortunately).

I've tried NULL in the hope that SQLServer will work it out but it complains. I don't want to do a 'SELECT IDENT_CURRENT('my_table')' prior to the INSERT due to the overhead and potential concurrency problems. Is there some special keyword or similar I can put in here?

DB is SQLServer2000 SP2. Any help is greatly appreciated.

Cheers,
Jim.Sounds like you have an application that was designed to run against diffrent vendor databases OR someone has missed the design boat. I don't understand why you would define a table with an identity attribute AND have a requirment that you pass a value for the identity value.

To my knowledge there is no way to pass a place hold in the fashion you have described.|||Originally posted by Paul Young
Sounds like you have an application that was designed to run against diffrent vendor databases OR someone has missed the design boat. I don't understand why you would define a table with an identity attribute AND have a requirment that you pass a value for the identity value.

The reason is that the app talks to a number of different back-end databases and they all have different ways of doing an insert on a table with a unique ID. For instance, Postgres expects to have nextval('my_table_f_id_seq') or similar in place of the %s. I'm just stuck (really stuck, as it turns out) with coding to the supplied spec.

Thanks for the reply.|||SET IDENTITY_INSERT my_table ON

INSERT INTO my_table(my_id,my_val)
VALUES (IDENT_CURRENT('my_table') + 1, 5)

SET IDENTITY_INSERT my_table OFF

May want to replace the + 1 with call to function IDENT_INCR()

Tim S|||Tim, that works a treat. Thanks!

Wednesday, March 7, 2012

Inserting via a view

Hello All, I have an strange issue regarding inserts via a view. Below are
the environemnts and the code. Both environments are identical however,
service packs a different.
Environment 1: This environmnet the insert works
Microsoft SQL Server 2000 - 8.00.760 (Intel X86)
Windows 2k sp4
Environment 2: This envirnoment the insert fails
Microsoft SQL Server 2000 - 8.00.818 (Intel X86)
Here is the insert statment;
INSERT INTO vMoxyStandardRestriction ( R.RestrictionID,
R.RestrictionType,
R.SecAssocType,
R.RestrictionName,
R.CanOverride,
D.TranCodeBits,
D.MinCompRestPercent,
D.MaxCompRestPercent,
D.IsAggregate,
D.RoundOption,
D.RoundFactor,
D.MinShares,
D.MinValue,
D.CompType)
VALUES (11, 1, 16, 'Unreconciled', 1, 12, 0.000000000000000e+000,
0.000000000000000e+000, 0, 0, 0.000000000000000e+000, 0.000000000000000e+000
,
0.000000000000000e+000, 0)
Here is the code to the view
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
ALTER VIEW vMoxyStandardRestriction AS
SELECT R.RestrictionID, R.RestrictionType, R.SecAssocType,
R.RestrictionName, R.CanOverride,
D.TranCodeBits, D.MinCompRestPercent, D.MaxCompRestPercent, D.IsAggregate,
D.RoundOption, D.RoundFactor, D.MinShares, D.MinValue, D.CompType
FROM MoxyRestriction R, MoxyRestDef D
WHERE R.RestrictionID = D.RestrictionID
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GOThis is the error message in the environment which does not work.
Server: Msg 4405, Level 16, State 2, Line 1
View or function 'vMoxyStandardRestriction' is not updatable because the
modification affects multiple base tables.
"FredG" wrote:

> Hello All, I have an strange issue regarding inserts via a view. Below are
> the environemnts and the code. Both environments are identical however,
> service packs a different.
> Environment 1: This environmnet the insert works
> Microsoft SQL Server 2000 - 8.00.760 (Intel X86)
> Windows 2k sp4
> Environment 2: This envirnoment the insert fails
> Microsoft SQL Server 2000 - 8.00.818 (Intel X86)
> Here is the insert statment;
> INSERT INTO vMoxyStandardRestriction ( R.RestrictionID,
> R.RestrictionType,
> R.SecAssocType,
> R.RestrictionName,
> R.CanOverride,
> D.TranCodeBits,
> D.MinCompRestPercent,
> D.MaxCompRestPercent,
> D.IsAggregate,
> D.RoundOption,
> D.RoundFactor,
> D.MinShares,
> D.MinValue,
> D.CompType)
> VALUES (11, 1, 16, 'Unreconciled', 1, 12, 0.000000000000000e+000,
> 0.000000000000000e+000, 0, 0, 0.000000000000000e+000, 0.000000000000000e+0
00,
> 0.000000000000000e+000, 0)
> Here is the code to the view
> SET QUOTED_IDENTIFIER OFF
> GO
> SET ANSI_NULLS OFF
> GO
> ALTER VIEW vMoxyStandardRestriction AS
> SELECT R.RestrictionID, R.RestrictionType, R.SecAssocType,
> R.RestrictionName, R.CanOverride,
> D.TranCodeBits, D.MinCompRestPercent, D.MaxCompRestPercent, D.IsAggreg
ate,
> D.RoundOption, D.RoundFactor, D.MinShares, D.MinValue, D.CompType
> FROM MoxyRestriction R, MoxyRestDef D
> WHERE R.RestrictionID = D.RestrictionID
> GO
> SET QUOTED_IDENTIFIER OFF
> GO
> SET ANSI_NULLS ON
> GO|||Hi Fred
Your error messages seems pretty explicit. You cannot insert into a view
that is based on a join. If you could, your single insert would have to put
rows into both the underlying tables, and according to BOL:
[If you insert into a view] .. the modifications made by the INSERT
statement cannot affect more than one of the base tables referenced in the
FROM clause of the view. For example, an INSERT into a multitable view must
use a column_list that references only columns from one base table.
If you are not getting the message for one of your servers, that is the
weirdness. Perhaps you have an INSTEAD OF TRIGGER on the view on that
server.
HTH
Kalen Delaney, SQL Server MVP
www.solidqualitylearning.com
"FredG" <FredG@.discussions.microsoft.com> wrote in message
news:B1BE7DA5-30D1-41F7-8C63-E213DA147DFA@.microsoft.com...
> Hello All, I have an strange issue regarding inserts via a view. Below are
> the environemnts and the code. Both environments are identical however,
> service packs a different.
> Environment 1: This environmnet the insert works
> Microsoft SQL Server 2000 - 8.00.760 (Intel X86)
> Windows 2k sp4
> Environment 2: This envirnoment the insert fails
> Microsoft SQL Server 2000 - 8.00.818 (Intel X86)
> Here is the insert statment;
> INSERT INTO vMoxyStandardRestriction ( R.RestrictionID,
> R.RestrictionType,
> R.SecAssocType,
> R.RestrictionName,
> R.CanOverride,
> D.TranCodeBits,
> D.MinCompRestPercent,
> D.MaxCompRestPercent,
> D.IsAggregate,
> D.RoundOption,
> D.RoundFactor,
> D.MinShares,
> D.MinValue,
> D.CompType)
> VALUES (11, 1, 16, 'Unreconciled', 1, 12, 0.000000000000000e+000,
> 0.000000000000000e+000, 0, 0, 0.000000000000000e+000,
> 0.000000000000000e+000,
> 0.000000000000000e+000, 0)
> Here is the code to the view
> SET QUOTED_IDENTIFIER OFF
> GO
> SET ANSI_NULLS OFF
> GO
> ALTER VIEW vMoxyStandardRestriction AS
> SELECT R.RestrictionID, R.RestrictionType, R.SecAssocType,
> R.RestrictionName, R.CanOverride,
> D.TranCodeBits, D.MinCompRestPercent, D.MaxCompRestPercent,
> D.IsAggregate,
> D.RoundOption, D.RoundFactor, D.MinShares, D.MinValue, D.CompType
> FROM MoxyRestriction R, MoxyRestDef D
> WHERE R.RestrictionID = D.RestrictionID
> GO
> SET QUOTED_IDENTIFIER OFF
> GO
> SET ANSI_NULLS ON
> GO
>

Inserting values in a datetime field

Hi All,
I have a datetime column in a table on the SQL database. I need to insert
values into the datetime column from vb.net code. Here is my code:
dim nameval, str, qry as string
nameval = "abc"
str = "2005/03/16 14:20"
qry = "insert into tab1(name,dateval) values(" & "'" & nameval & "'," & "'"
str & "')"
...
..
ocmd.ExecuteNonQuery()
...
...
The error message that I get is as follows:
"The conversion of a char data type to a datetime data type resulted in an
out-of-range datetime value. The statement has been terminated. .Net
SqlClient Data Provider"
The problem I think is due to passing a string for a datetime field. My
question is, if I convert the string to datetype using CDate(str), then I
would have to again convert the date to string in order to form the insert
statement. So, the ultimate result will be again passing a string for the
datetime field!
I know that this is a simple syntax problem, which I don't seem to get right
!
Would anybody be able to give me insert statement for the above?
Thanks.
kdkd
Format the parameter as 'YYYYMMDD'
"kd" <kd@.discussions.microsoft.com> wrote in message
news:FC6115C1-BD59-4B91-A237-6E10C38EB3A8@.microsoft.com...
> Hi All,
> I have a datetime column in a table on the SQL database. I need to insert
> values into the datetime column from vb.net code. Here is my code:
> dim nameval, str, qry as string
> nameval = "abc"
> str = "2005/03/16 14:20"
> qry = "insert into tab1(name,dateval) values(" & "'" & nameval & "'," &
"'"
> str & "')"
> ...
> ..
> ocmd.ExecuteNonQuery()
> ...
> ...
> The error message that I get is as follows:
> "The conversion of a char data type to a datetime data type resulted in an
> out-of-range datetime value. The statement has been terminated. .Net
> SqlClient Data Provider"
> The problem I think is due to passing a string for a datetime field. My
> question is, if I convert the string to datetype using CDate(str), then I
> would have to again convert the date to string in order to form the insert
> statement. So, the ultimate result will be again passing a string for the
> datetime field!
> I know that this is a simple syntax problem, which I don't seem to get
right!
> Would anybody be able to give me insert statement for the above?
> Thanks.
> kd
>

Sunday, February 19, 2012

Inserting Records

pls i have this issue on inserting records into SQL SERVER Express. this is the code so far :-

imports system.data

imports system.data.sqlclient

Protected

Sub btn1_Click(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles btn1.ClickDim strConnAsString = ConfigurationManager.ConnectionStrings("Connect1").ConnectionStringDim ObjConnAsNew SqlConnection(strConn)Dim strCommAsString ="insert Products(ProductName,UnitPrice) values(@.ProductName,@.UnitPrice)"Dim ObjCommAsNew SqlCommand(strComm, ObjConn)

ObjComm.Parameters.AddWithValue(

"@.ProductName", txtprodname.Text)

ObjComm.Parameters.AddWithValue(

"@.UnitPrice", SqlDbType.Money).Value = txtprice.Text

ObjConn.Open()

ObjComm.ExecuteNonQuery()

ObjConn.Close()

EndSub

End

Class

The issue i have is that anytime i click the button to insert a new record, i get two records added to the database automatically

What does the declaration for btn1_Click look like on your .aspx page?|||

tmorton:

What does the declaration for btn1_Click look like on your .aspx page?

pls i dont understand what u mean by declaration for btn1_Click. PLs elaborate.

thanks

|||Sorry, I am trying to ask what the <asp:button declaration looks like for btn1.|||

tmorton:

Sorry, I am trying to ask what the <asp:button declaration looks like for btn1.

Do U mean the On_Click event handler ? If so i used it as

<asp:Button ID="btn1" runat="server" OnClick="btn1_Click"/> if u are still not satisfied with these please recommend a site where i can have a guide or u please help withsome sample codes

|||

websyd:

Do U mean the On_Click event handler ? If so i used it as

<asp:Button ID="btn1" runat="server" OnClick="btn1_Click"/> if u are still not satisfied with these please recommend a site where i can have a guide or u please help withsome sample codes


Yes, that's what I meant. You basically have wired up the Click event twice, as you have it present in your Button declaration, as well as in your "Handles" clause. See Mike Pope's blog post for a bit more explanation:Documenting Event Handlers. You need to remove it from one place or the other, then the code will only run one time. I'd probably just remove the Handles clause from this code:

Sub btn1_Click(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles btn1.Click|||Great Guy, U hav made me happy with this forum again. It worked perfectly OK. Thanks i hope i can always right u to solve my problems as regards ASP.NET

INSERTING or UPDATING automatically

i am using visual web developer 2005 and SQL Express 2005 with VB as the code behind

i have a button and in the button click event i have written codes to INSERT to a database table - it has one primary key

so when i click the button, if there is already a row with primary key fields value as 10 and if i try to INSERT with the same value in the primary key field there will occur primary key constraint

so , if i try to INSERT with the already existing primary key fields value, instead of INSERTing it should be UPDATEd without generating any error

please help me

In ur SQl procedure

Include


If exists (select [PrimaryKeyColumn] from UrTable where PrimarKey = @.PrimaryKey)

Update ...

else

Insert ...

Like this u get to check for existing key , if exists it will execute an update else an insert

Hope that helps u