We help IT Professionals succeed at work.

Need connection string for SQL 2008.

92 Views
Last Modified: 2019-02-22
Hello all,

I need a connection string from c# to SQL server 2008.

The code below doesn't work.

Provider = SQLOLEDB; Server = ServerName; User id = UserName; Password = ThePassword; Database = TheDB

I get Invalid connection string attribute

I'm using ADODB.
Comment
Watch Question

Bill PrewTest your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016

Commented:
I forget exactly what 2008 needed, but try this newer syntax:

"Provider=SQLOLEDB;Data Source=serverName;Initial Catalog=databaseName;User ID=MyUserID;Password=MyPassword;"

Open in new window


»bp
Sheldon LivingstonConsultant

Author

Commented:
Bill... I get the error that my server doesn't exist.
Bill PrewTest your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016

Commented:
Are you able to connect to that server any other way from the client, via SQLCMD or SSMS, etc?


»bp
Sheldon LivingstonConsultant

Author

Commented:
Via RDP.
Bill PrewTest your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016

Commented:
Well, that's connecting to it as a RDP server, not a SQL Server database server.  It sounds like SQL Server may not be running there currently.


»bp
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2015

Commented:
www.connectionstrings.com - The connection string bible as it were.

Specifically:  https://www.connectionstrings.com/sql-server-2008/
Qlemo"Batchelor", Developer and EE Topic Advisor
CERTIFIED EXPERT
Top Expert 2015

Commented:
Make sure to not use spaces before =, and better not to do that after either.
Provider= SQLOLEDB; Server= ServerName; User id= UserName; Password= ThePassword; Database=TheDB

Open in new window

should work - if you made sure you can connect to MSSQL from remote at all.
Sheldon LivingstonConsultant

Author

Commented:
This is a functioning SQL Server with web pages on it.
Bill PrewTest your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016

Commented:
Just to be clear, web pages would come off of an IIS web server, not a SQL Server database server.

Both could be active on the same server, but just to clarify...


»bp
Sheldon LivingstonConsultant

Author

Commented:
Right... I have a webserver that has SQL on it.  What I'm trying to do is write a piece of software that monitors and email address.  Once it sees an email it will parse it and update some fields in a SQL database.

Currently the program can pull the email and parse it.

What I thought would be a no brainer (connecting to SQL) is the most difficult part.
Qlemo"Batchelor", Developer and EE Topic Advisor
CERTIFIED EXPERT
Top Expert 2015

Commented:
Your software find runs on the server, or remote?
Sheldon LivingstonConsultant

Author

Commented:
Qlemo... I don't know what "Your software find on the server, or remote?" means.
Sam JacobsCitrix Technology Professional / Director of TechDev Services, IPM
CERTIFIED EXPERT

Commented:
Sheldon ... can you create a SQL Server ODBC connection to the SQL Server and see your databases in the wizard ?
ODBC-Connection.jpg
Sheldon LivingstonConsultant

Author

Commented:
Sam... I cannot.  Doesn't see the server:
ODBC
Sam JacobsCitrix Technology Professional / Director of TechDev Services, IPM
CERTIFIED EXPERT

Commented:
Ok ... that means that SQL is not listening for connections (or cannot resolve the name).
Can you connect via IP address?
Can you TELNET <ip address> 1433  (assuming you're using the default SQL port)?
If not, you might want to start by rebooting the server (if you haven't already).
Sheldon LivingstonConsultant

Author

Commented:
I can RDP via the IP address... the local IP address (non-routed 10.x)
I'll need to install Telnet later.
Server is working fine and not needing a reboot.  It is a webserver and is serving up pages fine.
Sam JacobsCitrix Technology Professional / Director of TechDev Services, IPM
CERTIFIED EXPERT

Commented:
As Bill mentioned earlier, IIS and SQL Server are different services (IIS listens on 800/443, and SQL listens on 1433), so just because one is working, doesn't mean that the other is.
If you RDP to the server, can you connect to the databases with SQL Server Management Studio?
Sheldon LivingstonConsultant

Author

Commented:
Yes I can connect to the server via RDP and the studio.  That is how I maintain it.
Citrix Technology Professional / Director of TechDev Services, IPM
CERTIFIED EXPERT
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
Sheldon LivingstonConsultant

Author

Commented:
So... I shut down the FW and could connect.  I then turned on the FW and made an inbound rule for 1433 and it worked.

Thank you Sam!
Sam JacobsCitrix Technology Professional / Director of TechDev Services, IPM
CERTIFIED EXPERT

Commented:
Cool ... I hate firewalls, but unfortunately, they are a necessary evil! :)
Sheldon LivingstonConsultant

Author

Commented:
Thanks again Sam!
Bill PrewTest your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016

Commented:
Glad you got that resolved Sheldon, well done Sam.


»bp
Sam JacobsCitrix Technology Professional / Director of TechDev Services, IPM
CERTIFIED EXPERT

Commented:
@Sheldon ... you are most welcome.

@Bill ... Thanks.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions