SQL Stored Proc Permissions

Hi Experts

I have a SQL Server that I need to run some stored procs on, however... I believe it to be a permissions issue as the Stored Proc creates successfully..

here it is..

-- ================================================
-- Template generated from Template Explorer using:
-- Create Procedure (New Menu).SQL
--
-- Use the Specify Values for Template Parameters 
-- command (Ctrl-Shift-M) to fill in the parameter 
-- values below.
--
-- This block of comments will not be included in
-- the definition of the procedure.
-- ================================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE InsertGuests

@G_One_FirstName varchar (28) , 
@G_One_SecondName varchar (28), 
@G_Two_FirstName varchar (28) , 
@G_Two_SecondName varchar (28) ,
@Children decimal,
@Teens decimal,
@GuestType varchar (12),
@AddressLine1 varchar (64),
@AddressLine2 varchar (64),
@AddressLine3 varchar (64),
@Postcode varchar (10),
@Responded varchar (3) , 
@Attending Varchar (24) 
	
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	Insert Into dbo.WeddingGuest (G_One_FirstName, G_One_SecondName, G_Two_FirstName, 
	G_Two_SecondName, Children, Teens, GuestType, AddressLine1, AddressLine2,
	AddressLine3, Postcode, Responded, Attending)
	Values (@G_One_FirstName, @G_One_SecondName, @G_Two_FirstName, 
	@G_Two_SecondName, @Children, @Teens, @GuestType, @AddressLine1, @AddressLine2,
	@AddressLine3, @Postcode, 'No', 'TBC');
END
GO
 

Open in new window


What I am after is how do I get the sa account or create another account in order to allow the insert statement to be executed from an ASP.Net website from the Internet..

thanks

and yes.. I can connect into the database as have tested this already..
SimonPrice33Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kyle AbrahamsSenior .Net DeveloperCommented:
Easiest way is to create a user with DBO permissions to the DB in question.

add this to your webconfig:
<configuration>
  <connectionStrings>
<add name="ConnectionString" connectionString="Provider=SQLOLEDB;Data Source=<DB SERVER NAME>;Password=<SQL PASSWORD>;User ID=<SQL USER>;Initial Catalog=<THE DATABASE>;Connect Timeout=<TIME IN SECONDS>;" providerName="System.Data.OleDb" />
  </connectionStrings>

and in your code when specifying the Connection you would do:

SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString());

Hope that answers your question.  How are you connecting to the DB now?

have you executed the SP via an execute statement on the DB and does that work?
0
SimonPrice33Author Commented:
the connection to open the database connection works perfectly...  I will copy my code up in a second..

i didnt have .tostring on the end so maybe that will make a difference, however I already have it declared as a string ..
0
SimonPrice33Author Commented:
nope... didnt work..

Imports System.Data.SqlClient
Imports System.Data.Sql
Imports System.Data
Imports System.IO

Public Class guests
    Inherits System.Web.UI.Page


    Dim sqldr As SqlDataReader
    Dim sqlcmd As New SqlCommand
    Dim connstr As String = ConfigurationManager.ConnectionStrings("Database").ConnectionString.ToString
    Dim SqlConn As New SqlConnection
    Dim sqlstr As String = Nothing




    Protected Sub bttnSubmit_Click(sender As Object, e As System.EventArgs) Handles bttnSubmit.Click

        Dim G1Name1 As New SqlParameter("@G_One_FirstName", SqlDbType.NVarChar)
        G1Name1.Value = tbFirstGuestName1.Text
        Dim G1Name2 As New SqlParameter("@G_One_SecondName", SqlDbType.NVarChar)
        G1Name2.Value = tbFirstGuestName2.Text
        Dim G2Name1 As New SqlParameter("@G_Two_FirstName", SqlDbType.NVarChar)
        G2Name1.Value = tbSecondGuestName1.Text
        Dim G2Name2 As New SqlParameter("@G_Two_SecondName", SqlDbType.NVarChar)
        G2Name2.Value = tbSeconsGuestName2.Text
        Dim Children As New SqlParameter("@Children", SqlDbType.Decimal)
        Children.Value = ddlChildren.SelectedValue
        Dim Teens As New SqlParameter("@Children", SqlDbType.Decimal)
        Teens.Value = ddlTeens.SelectedValue
        Dim GuestType As New SqlParameter("@Teens", SqlDbType.NVarChar)
        GuestType.Value = ddlGuestType.SelectedValue
        Dim Address1 As New SqlParameter("@Address1", SqlDbType.NVarChar)
        Dim Address2 As New SqlParameter("@Address2", SqlDbType.NVarChar)
        Dim Address3 As New SqlParameter("@Address3", SqlDbType.NVarChar)
        Address1.Value = tbAddress1.Text
        Address2.Value = tbAddress2.Text
        Address3.Value = tbAddress3.Text
        Dim PostCode As New SqlParameter("@PostCode", SqlDbType.NVarChar)
        PostCode.Value = tbPostCode.Text




        Try

            With sqlcmd
                .CommandType = CommandType.StoredProcedure
                .CommandText = "InsertGuests"
                .Parameters.Add(G1Name1)
                .Parameters.Add(G1Name2)
                .Parameters.Add(G2Name1)
                .Parameters.Add(G2Name2)
                .Parameters.Add(Children)
                .Parameters.Add(Teens)
                .Parameters.Add(GuestType)
                .Parameters.Add(Address1)
                .Parameters.Add(Address2)
                .Parameters.Add(Address3)
                .Parameters.Add(PostCode)
                .Connection = SqlConn
            End With
            SqlConn.ConnectionString = connstr
            SqlConn.Open()
            sqlcmd.ExecuteNonQuery()
            SqlConn.Close()

            tbFirstGuestName1.Text = Nothing
            tbFirstGuestName2.Text = Nothing
            tbSecondGuestName1.Text = Nothing
            tbSeconsGuestName2.Text = Nothing
            ddlChildren.SelectedIndex = 0
            ddlTeens.SelectedIndex = 0
            ddlGuestType.SelectedIndex = 0
            tbAddress1.Text = Nothing
            tbAddress2.Text = Nothing
            tbAddress3.Text = Nothing
            tbPostCode.Text = Nothing
        Catch ex As Exception
            Response.Write("Record Not Saved " & e.ToString)
        End Try

    End Sub

    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load


        

    End Sub

    Protected Sub GridView1_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles GridView1.SelectedIndexChanged

    End Sub
End Class

Open in new window

0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Kyle AbrahamsSenior .Net DeveloperCommented:
For VB it shouldn't matter you're fine there.

Are you getting an exception?  

Just as a note you can do this
    Dim SqlConn Dim connstr As String = ConfigurationManager.ConnectionStrings("Database").ConnectionString.ToString
    Dim SqlConn As New SqlConnection
in one step:

 As SqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings("Database").ConnectionString.ToString()
)

Also just another note you're passing Nvarchars (vs varchar) in your code vs the stored proc . . . one is unicode the other is not and may be causing issues.


Besides that looks okay at first glance.  Leaving for today, let me know if you get an exception or what you're seeing/ not seeing.
0
SimonPrice33Author Commented:
could be the declarations.. will check them now...
0
SimonPrice33Author Commented:
changed the sqldbtype.nvarchar to sqldbtype.varchar but still get the same error

System.EventArgs

which is useless for me...
0
SimonPrice33Author Commented:
it seems it didnt like the int values... changed them to varchar too and has gone through ok...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SimonPrice33Author Commented:
.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.