Click here to Skip to main content
Rate this: bad
good
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
Edited 16-Nov-12 4:39am
v2
Rate this: bad
good
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. http://www.connectionstrings.com/[^]
  Permalink  
Comments
MitchG92_24 at 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
good
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.
  Permalink  
Comments
MitchG92_24 at 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 at 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
0 OriginalGriff 428
1 Sergey Alexandrovich Kryukov 283
2 PhilLenoir 115
3 RajeeshMenoth 110
4 Peter Leow 100
0 Sergey Alexandrovich Kryukov 6,465
1 OriginalGriff 5,926
2 CPallini 2,473
3 Richard MacCutchan 1,687
4 Abhinav S 1,540


Advertise | Privacy | Mobile
Web03 | 2.8.140821.2 | Last Updated 16 Nov 2012
Copyright © CodeProject, 1999-2014
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