473,320 Members | 2,029 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

connect to SQL server from c# program

17
Hi,
I want to add SQL server to my c# project ,I'm working on visual studio 2005
when i added the server i could not connect it.
can some one help me with it ?
thanks
Oct 24 '08 #1
7 2215
Plater
7,872 Expert 4TB
check your connection string?
http://www.connectionstrings.com

Is the server configured to allow connections? Does your program run with the user credentials to use the SQL server?
Oct 24 '08 #2
Frinavale
9,735 Expert Mod 8TB
What errors are you getting?
What have you tried so far?
Do you know how to use an database in your program?
If not maybe this article might help....

-Frinny
Oct 24 '08 #3
eranby
17
Hi,
sorry for the lack of information I'm new to SQL server hence my problem could be something very simple such as configuration issue that I'm not familiar with.

I used a string which I took from a web site I don't know if it is very helpful:
SqlConnection con = new SqlConnection("user id=username;" +
"password=password;server=serverurl;" +
"Trusted_Connection=yes;" +
"database=database; " +
"connection timeout=30");
trying to open connection with it results this run time error :
An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
I looked for this error but found nothing useful
hope it help you to understand my problem please let kow if you need any other details

thanks
Oct 24 '08 #4
Plater
7,872 Expert 4TB
That's close to the write connection string
"Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;"
http://www.connectionstrings.com/?carrier=sqlserver2005

Scroll down to the SqlConnection (.NET) section
Oct 24 '08 #5
eranby
17
I used the string you gave me and some others from the link but I'm still receiving the same error.
are the parameters in the string should be changed in my application or they are the same for every connenction?
and something about the error - it indicates that the server does not allow remote connection by default is it something in the configuration that I should set when adding the server?
thanks
Oct 24 '08 #6
Plater
7,872 Expert 4TB
Yes you will need to make sure to configure the SQL server to allow incomming connection.
And I would hope you would know to change the parameter names from "username" to an actual username.
What is the connection string you are using now?
Oct 27 '08 #7
eranby
17
Hi ,
thank you for your help.
as I thought it was something very simple.
I added reference to System.configuration and add Using System.configuration to the code and used this code in order to connect the server :
ConnectionStringSettings settings =
ConfigurationManager.ConnectionStrings["StockDB"];
con = new SqlConnection(settings.ConnectionString);
it solve the problem :)

thanks again
Eran
Oct 31 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Marcus | last post by:
Hello! I'm trying to write a VB.NET program that connects to a AS/400 Server. I've tried almost everything, but it will not connect. I've tried to set up a DSN using the Client Access...
6
by: Jerry Orr | last post by:
We are trying to determine the easiest (and cheapest) way to get connections for about 50 Win2K workstations on our LAN to DB2 on a z/OS server. We could install DB2 Connect Personal Edition on...
4
by: Scott Holland | last post by:
HELP - Need to connect to DB2 database on AIX from NT server. Also AS/400 from NT Server -- I am experienced in ORACLE and a novice at DB2. What tools would be the equivalent of Net*8 or...
2
by: iwdu15 | last post by:
hey, i was wondering if 1) anyone could tell me whats wrong with my code, i did a little fixing to the msdn version fo this, or 2) how to make a simple program that will connect and listen for...
14
by: Marcus | last post by:
I have a function that simply returns TRUE if it can connect to a particular Sql Server 2005 express, or FALSE if it cannot. I am getting some strange error codes returned when the computer that...
3
by: RFD | last post by:
I've been slaving at this problem for over a week, and would appreciate some help from you kind folks. Basic Problem: I have made a server program and a client program. When I try to use the...
0
by: Neff | last post by:
I have a clustered installation of SQL Server 2005 with SSIS installed on the cluster. I'm running SQL Server Management Server on one of the cluster nodes and trying to connect to the...
3
by: arasub | last post by:
ep 20, 2007 11:25:57 AM org.apache.catalina.core.AprLifecycleListener lifecycleEvent INFO: The Apache Tomcat Native library which allows optimal performance in production environments was not found...
2
by: 7stud | last post by:
According to "Python in a Nutshell(2nd)", p. 523: connect: s.connect((host, port)) .... Blocks until the server accepts or rejects the connection attempt. However, my client program ends...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.