Click here to Skip to main content
12,556,918 members (47,728 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# SQL connection
Hi All,

I've tried researching this but can't find anything black and white, and this sites always been helpful.

I have an object called "EventLog" that i need to pass into an existing SQL database as a row, this database has a stored procedure named "CreateNewEventEntry".

Server name = SERVER
Database name = DB
Integrated Security = SSPI

My PC has been given permission to access this database so that won't be a problem.

What sort of syntax do i use to connect to this server/database and use the stored procedure?
Posted 16-Nov-12 4:29am
Updated 16-Nov-12 4:39am
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

try this:-SqlConnection myConnection = new SqlConnection("Data Source=SERVERNAME; Initial Catalog=DATABASENAME; User Id = Your_userid ;Password = Your_Password;");

Please refer this page.[^]
MitchG92_24 19-Nov-12 6:43am
Thank you, very useful site. I ended up using:

SqlConnection connection = new SqlConnection("Server=SERVERNAME; Initial Catalog=DATABASENAME; Integrated Security=SSPI; connection timeout=30");

And contacted the stored procedure by:

SqlCommand spcmd = new SqlCommand(storedProcedure, connection);
spcmd.CommandType = System.Data.CommandType.StoredProcedure;
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You really can't use google to work out how to connect to a database ? Or even search Code Project[^] ?

What sort of object is 'EventLog' ? You can't pass a class in to SQL Server, only basic types like strings and ints.
MitchG92_24 16-Nov-12 10:43am
Sorry, I've been trial and erroring to no avail, so i was hoping for the syntax for the connectionString that i need as i can't find that anywhere. And i'd like to pass string and int values that belong to EventLog Class.
Christian Graus 16-Nov-12 10:45am
We can't give you the syntax without knowing the details, nor can we know you need that if it's not what you asked. You need to pass those values individually, you can't pass the actual class in a meaningful way.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.161026.1 | Last Updated 16 Nov 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100