Click here to Skip to main content
Sign Up to vote bad
good
See more: C#SQLconnection
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:29
Edited 16 Nov '12 - 4:39


2 solutions

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 - 19 Nov '12 - 6:43
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;
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 - 16 Nov '12 - 10:43
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:45
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
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 586
1 Maciej Los 255
2 Slacker007 240
3 OriginalGriff 220
4 CPallini 210
0 Sergey Alexandrovich Kryukov 9,118
1 OriginalGriff 7,134
2 CPallini 3,803
3 Rohan Leuva 3,135
4 Maciej Los 2,558


Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 16 Nov 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid