Click here to Skip to main content
15,891,204 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Updated 16-Nov-12 4:39am
v2

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/[^]
 
Share this answer
 
Comments
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;
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.
 
Share this answer
 
Comments
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900