0

Hi anybody can help me , i want to connect the sql serverdatase from local machine in windows application. i am trying this like this way but it give me an error my connection string

return new SqlConnection(@"Data Source=68.71.135.2,2121;Initial Catalog=DBTest;User ID=myId;Password=mypass;");

how i connect to server database.


Thanks in Advance...

4
Contributors
6
Replies
7
Views
5 Years
Discussion Span
Last Post by bhagawatshinde
0

Hi, Mitja Bonca i have allready see this link. SQLSERVER 2005
Let me explain what i have to do..
I am developing an desktop application. by using this application i want to connect server database which is online. (i.e website databse) but unable to connect server datase. i want to retrive as well as insert the values to server db.

0

If you use SQL Server Authentication (which is true this case) you must set Integrated Security parameter to false. This should work:

return new SqlConnection(@"Data Source=68.71.135.2,2121;Initial Catalog=DBTest;Integrated Security=False;User ID=myId;Password=mypass;");

Edited by jugosoft: n/a

0

To connect to SQL Server from C#.NET, you need to create a connection string such as below:

private SqlConnection connection; private string connectionString = @"Server=(local);Database=Embedding_SQL_Test;User ID=sa;Password=123"; connection = new SqlConnection( connectionString );

Next, you use the SqlConnection object created above to create a 'SqlCommand', as shown below:

SqlCommand cmd = new SqlCommand( "select * from Customer where CustomerID = @Cid", connection);

The SQL query shown here can be replaced by a SELECT, INSERT, UPDATE queries etc.

Next to execute the SQL queries in the database, you use the following methods:

ExecuteReader

- to execute SELECT queries

ExecuteNonQuery

- to execute INSERT, DELETE, UPDATE, and SET statements.

This is a very short description of how to connect to SQL Server database from C# and execute SQL queries in the database. For details about the connection string, the methods and their parameters check the following link: ( http://www.shahriarnk.com/Shahriar-N-K-Research-Embedding-SQL-in-C-Sharp-Java.html ) Here you will also find details about how to pass parameters to the SQL queries as well as calling stored procedures and much more.

0

Thanks SNK111,jugosoft,Mitja Bonca for valuable reply i found solution like see below code

Classic ASP (ADO Library)	Provider=SQLOLEDB;Data source=IP Address,Port No.;Initial catalog=databaseName;User Id=userName;Password=password;
ASP.NET (ADO.NET Library)	Server=IP Address,Port No.;Database=databaseName;Uid=userName;Password=password;
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.