Thread: Using SQL server in C#
June 30th, 2010, 03:22 AM #1
- Join Date
- Jun 2010
Using SQL server in C#
I am new to .net and SQL stuff. I was reading tutorials on google and got the syntax for establishing an SQL connection but could understand it. So if someone could explain in a better way?
SqlConnection myConnection = new SqlConnection("user id=username;" +
"database=databse; " +
i wanted to ask what should come in place of server url?
and also, what should be written in place of databse??
My database is named - "StuData" and is stored in path C:\myDataSrc.
I am using SQL server 2008.
August 8th, 2010, 09:43 AM #2
- Join Date
- Aug 2010
okk let me try
here SqlConnection is a class and myConnection is its object.
user id = it is used to specify the server login account
password=it is used to specify the login password for the server login account
server = it is the name of your server
database=it is the name of the database that you are working on
connection timeout = is the time in seconds to wait while a connection to the data source is attempted.
for example in sql server 2005 if my server name is sqlserver098 and database name is HR and user id =sam and password is 1234
then i will write the following query
SqlConnection connection=new SqlConnection();
and now gonna use the ConnectionString property of SqlConnection class
connection.ConnectionString="Data Source=sqlserver098;Initial Catalog=HR; User ID=sa;password=1234"
hope this helps
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
By gberz3 in forum Applications and Operating SystemsReplies: 0Last Post: May 2nd, 2009, 11:46 PM
By J1mmy in forum Networking and InternetReplies: 4Last Post: November 29th, 2005, 12:38 PM
By omalleytrading in forum Webmastering and ProgrammingReplies: 18Last Post: July 7th, 2003, 09:22 PM
By imd in forum Webmastering and ProgrammingReplies: 1Last Post: October 24th, 2002, 01:21 PM
By imd in forum Webmastering and ProgrammingReplies: 0Last Post: October 24th, 2002, 05:44 AM