Results 1 to 10 of 10

Thread: running stored procedure

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2010
    Posts
    5

    running stored procedure

    I am a VB newb running VB/VS 2010.
    I am trying to call a stored procedure from a SQLExpress2005 data base on a Windows 2003 Domain Controller. I keep having errors when I run my code in debug mode.

    Stored procedure name = InsertUsersFromAD
    Server name where SQL resides = MIS631
    Database Name = AdminGUI

    I have ******** rights on the dev PC and the servers

    My code is as follows:
    'Run Stored Procedure on SQL Database
    vb.net Code:
    1. Dim CONN As New SqlConnection
    2.                 CONN.ConnectionString = "Data Source = \\MIS631; Initial Catalog = AdminGUI; " & "Integrated Security = True"
    3.                 Dim sc As New SqlCommand("InsertUsersFromAD", CONN)
    4.                 sc.CommandType = CommandType.StoredProcedure
    5.                 CONN.Open()
    6.  
    7.                 sc.ExecuteNonQuery()
    8.                 sc.Connection.Close()
    I've tried making the Data Source = \\MIS631\SQLEXPRESS also, which didn't seem to work. Please help!!
    I am trying to finish up a school project and this is the only thing not working.
    Thanks so much.

  2. #2
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: running stored procedure

    I keep having errors when I run my code in debug mode.
    Tell us what the errors are and which line they are thrown on and we might be able to help
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  3. #3
    Frenzied Member stateofidleness's Avatar
    Join Date
    Jan 2009
    Posts
    1,780

    Re: running stored procedure

    there's no username or password in your connection string? you can also remove the "&" between the 2 parts of the connection string. They can be combined.

    www.connectionstrings.com

  4. #4
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: running stored procedure

    You dont have to use a username and password when you use Integrated Security because it means that it uses Windows Authentication (ie uses your logged on user credentials).

    I'm also pretty sure you dont need the \\ when specifying the server, but you will definitely need the \SQLEXPRESS bit if it is a default setup of SQL Express on the server. Its pretty hard to suggest things though when we dont know where it is failing - I mean it might be connecting to the server fine, just throwing an error when he tries to do ExecuteNonQuery
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  5. #5

    Thread Starter
    New Member
    Join Date
    Jun 2010
    Posts
    5

    Unhappy Re: running stored procedure

    I apologize for not providing needed information, like I said I'm a newb.

    I get an SQLException was unhandled -- error 25
    when it hits the line

    CONN.Open()

  6. #6

    Thread Starter
    New Member
    Join Date
    Jun 2010
    Posts
    5

    Re: running stored procedure

    OK, I took off the preceeding "\\" before the server name.

    "Now i get a SQLException error was unhandled" message at the same line, but is says that the user is not associated with a trusted SQL server connection.

    I am a domain admin, server admin, sql admin, local workstation admin.
    So the error changed slightly, but the code still hangs at the same line.

  7. #7
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: running stored procedure

    Are you 100% sure that your windows user account that you are logged on with actually has permission to access that SQL database though? Just because you are a domain admin doesnt necessarily mean you have permission to every single database within an SQL instance. Also, assuming this application is going to be for more people than just yourself to use, have you thought about if they are going to have permission to the database as well?
    Just to test to see if it is a permissions issue, see if you can log in to the SQL instance via SQL Management Studio using your windows credentials.
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  8. #8

    Thread Starter
    New Member
    Join Date
    Jun 2010
    Posts
    5

    Re: running stored procedure

    Yes sir. I assure you that I can log into the database with my credentials. I can also browse through server objects from my client PC that is running VB using the Server Explorer. I have also checked the firewalls

  9. #9
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: running stored procedure

    Hmm ok well just try this code exactly as it is and see if you still get an exception on the call to CONN.Open()

    Code:
    Dim CONN As New SqlConnection("Server=MIS631\SQLEXPRESS; Database=AdminGUI; Trusted_Connection=True;")
    CONN.Open()
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  10. #10

    Thread Starter
    New Member
    Join Date
    Jun 2010
    Posts
    5

    Re: running stored procedure

    THAT DID IT!!
    Thanks so much. I have never used VB before and my first attempt is for an application that I am making for my Masters project. I am basically writing a new interface for AD Users and Computers, it is a very grandiose attempt for my first time programming.

    THANKS SO MUCH!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width