Error in remote connection to SQL Server

G

glbdev

Hi. I am having an problem connecting to a remote SQL Server. Other
applications (using access) are connection to it but I cannot get it
to work through ASP.Net.

Here is my connection string:

Public Function StringConnection() As String
Return "Server=myservername;Database=mydatabasename;User
ID=myid;Password=mypassword;"
End Function

Everything works fine if I use my local DB so I am sure it's not the
code and other applications can connect to the server so I am pretty
sure it's not SQL Server, something must be wrong in the connection
string. The sample above is just the latest version I've tried. I'm
only posting it in the hope that someone can show me the correct
string for a remote connection.

Any ideas?

Thanks,
Steve
 
P

Peter Bromberg [C# MVP]

You'd be a lot better off if you didn't hard-code the connection string into
your compiled code. Better to use the app.config / web.config
ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString
or an <appSettings> section instead. This makes your application more
portable.

If, as you say, other applications can connect to the server ( i assume
remotely) then why don't you take a look at their connection strings?
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
MetaFinder: http://www.blogmetafinder.com
 
P

Peter Bromberg [C# MVP]

If you are using the "Web Site" project model, you need to place all your
global.asax code in global.asax.cs, in the App_Code directory

You must include this at the top of global.asax.cs :

public class Global : System.Web.HttpApplication

.....and include this directive in global.asax :
<%@ Application Language="C#" CodeBehind="Global.asax.cs" Inherits="Global" %>

the same for vb :
<%@ Application Language="VB" CodeBehind="Global.asax.vb" Inherits="Global" %>

With a Web Application Project, this is not necessary and you can use the
normal (like in 1.1 that is) codebehind deal.
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
MetaFinder: http://www.blogmetafinder.com
 
S

sloan

A remote server must be enabled to receive remote connections.

This is via the "Sql Server Surface Area Configuration".

if that is setup properly, there are 2 things.


www.connectionstrings.com

keeping playing with them.

and (default)....the port is 1433..you have to make sure this is open...via
a firewall program you are using.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top