help connecting over the web

  • Hey.

    I'm new to SQL server. Can someone explain to me how I connect to the SQL server that is on my computer, from a web page? I have created an ASP page and uploaded it onto a web server, but I need to be able to read from my database that is on SQL server on my computer? how do I do this?

  • In ASP.NET, you can try this code:

     

    string MyConnectionString =

    string.Format("Provider=SQLOLEDB; Data Source={0}; " +

    " Initial Catalog={1};User ID={2}; Password={3}",

    URL, DBName, UserID, Password);

    OleDbConnection _connection = new OleDbConnection(MyConnectionString);

    _connection.Open();

    string sql = "SELECT TOP 1 * FROM MyTable";

    OleDbDataAdapter da = new OleDbDataAdapter(sql, _connection);

    DataSet ds = new DataSet();

    da.Fill(ds);

  • Ok, but what do I use for values? like, what do I use for data source, or what is the url to my computer? do I use my IP address anywhere? please explain how this works. If I'm connection from a website to my computer, my computer would have to be on so that the website can access it, right? Or does the ASP page always need to be on the same server as the SQL server?

  • The datasource is the name of the database (such as Northwind)

    The URL is the IP address of the server (or 127.0.0.1 if the web server is on the same machine as the database)

    Many times the database is placed on its own server, and therefore you would have to use the real IP address of the server the database is on.

  • how do  I find out what my IP address is? when I type in IPCONFIG in dos, all it gives me is the IP address of my network, which is the generic 192.168.0.101. How do I find the one that I can actually use to connect to my computer?

  • I don't know the answer. If you install the client tools (Query Analyzer, etc..) on another computer, and try connecting using the various IP addresses it should be easy enough to figure it out.

    Rick

  • ipconfig returns your IP address.  I cannot imagine any configurations where it would not return your IP address.  Try using ipconfig /all and ipconfig /?

    if the DB is on your machine you can substitute localhost for the IP.


    Cheers,

    david russell

  • try visiting http://www.whatismyip.com

    That will tell you your external IP address, but this is only the address of your router, not necessarily YOUR ip. 

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic. Login to reply