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?

Improve company productivity with a Business Account.Sign Up

x
 
SimonPrice33Connect With a Mentor Author Commented:
it seems it didnt like the int values... changed them to varchar too and has gone through ok...
0
 
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
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
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
 
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:
.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.