none
how to connect host website with local database in asp.net in vb

    Question

  • hello,

    I have a question,i have a website that host in the server but i wanna my database in the local pc cause i wanna the database connect together with desktop application and web application here my connection string from the web

    <connectionStrings>
            <add name="WebApplication1.My.MySettings.Setting" connectionString="Data Source=CALEB-PC;Persist Security Info=True;User ID=userID;Password=Password"
                providerName="System.Data.SqlClient" />
            <add name="ConnectionString" connectionString="Data Source=CALEB-PC\;Persist Security Info=True;User ID=UserID;Password=Password"
                providerName="System.Data.SqlClient" />
        </connectionStrings>

    this connection string work for desktop application.

    I always have problem with my database connection string.

    Thank You

    Saturday, August 02, 2014 8:41 PM

Answers

  • Your connection options arre inconsistent, but I don't think that is the cause of the issue

    Persist Security Info=True;User ID=userID;Password=Password"

    When you use Persisted Info you don't need ID and password it uses the windows credentials and gets password from a pasword server that is common between client and server PC's.  I bet your desktop won't work if you use a remote PC that isn't in the local domain.

    I still think the followng is the issue

    I suspect the issue isn't the connection string but an issue with windows allowing remote connections.  What windows operating system is on the SQL Server machine?  You have to allow remote connections.   You need a user


    jdweng

    • Marked as answer by CalebJohnny Wednesday, August 06, 2014 6:11 AM
    Tuesday, August 05, 2014 2:46 PM
  • You will need to use the IP address of your local PC in the connection string you use on the web server: SQL Server connection strings.

    That will be a problem if your PC is connected to the Internet via NAT. Your router may be able to do port mapping. However, you may get a different IP address on the Internet side of your router occassionally or even most times you switch on the router.

    It is generally a Bad Idea to expose an SQL server to the Internet because malware will attack it.

    --
    Andrew

    Tuesday, August 05, 2014 3:53 PM
  • ...continued, as I had to go elsewhere suddenly.

    What you could do, to avoid exposing your local SQL server to attacks, is set up IIS on it and use WCF or such to provide services to the web application. That way, you can rigorously filter requests. Make sure that you use parameterised SQL queries, and use SQL stored procedures as far as possible rather than allowing arbitrary queries.

    However, seeing as the website will probably have a fixed IP address, you may be better off running the database on the web server and using WCF or such on it, then using WCF to connect to the server from the desktop program. Also, you will not have to have your computer switched on all the time for the web site to work, and if your Internet connection fails it will not break the website.

    HTH,

    Andrew

    • Marked as answer by CalebJohnny Wednesday, August 06, 2014 6:11 AM
    Tuesday, August 05, 2014 8:01 PM

All replies

  • Hello,

    Check out the answer on the following post and if that does not assist let us know.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

    Saturday, August 02, 2014 10:37 PM
    Moderator
  • hello,

    I have a question,i have a website that host in the server but i wanna my database in the local pc cause i wanna the database connect together with desktop application and web application here my connection string from the web

    <connectionStrings>
            <add name="WebApplication1.My.MySettings.Setting" connectionString="Data Source=CALEB-PC;Persist Security Info=True;User ID=userID;Password=Password"
                providerName="System.Data.SqlClient" />
            <add name="ConnectionString" connectionString="Data Source=CALEB-PC\;Persist Security Info=True;User ID=UserID;Password=Password"
                providerName="System.Data.SqlClient" />
        </connectionStrings>

    this connection string work for desktop application.

    I always have problem with my database connection string.

    Thank You

    Maybe you mean you always have problems with your web application connection string?

    Is the website PC hosting your web application on the same LAN that the PC containing your database is on? Or are they on separate networks? As determining information to use in a connection string can become an issue if they are on separate networks.

    However since you are using XML to create the connection strings perhaps it would be better to ask the question in one of the forums in the ASP.Net forums since people that provide answers in those forums would possibly have information available for what you need to know. Although it's possible you could be assisted to the extent necessary in this forum it is unlikely in my opinion.


    La vida loca


    Sunday, August 03, 2014 7:45 AM
  • Is Separate Network i guess cause i wanna my website to be online Web hosting and my database will be at local PC 

    Thank you.

    Sunday, August 03, 2014 8:58 AM
  • I have see the answer from martin but i cant really understand and my sqlserver is already allow remote connection just that when i open up http://enivre1717-001-site1.myasp.net/WebForm1.aspx this free hosting web it alway come up with error although my username and password are correct.

    Thank you

    Sunday, August 03, 2014 9:03 AM
  • Why are you using a free hosting web when you have a SQLServer application install on your PC.  So you have SQL Server Management Studio (SSMS) installed which wil allow you to connect to your own SQL Server?  SSMS login window contains the instanse of your SQL Server and in the SQL Explorer window the name of the database will be shown.  Both the instance and tthe DataBase name should be in your Conneciton String in your VS application.

    jdweng

    Sunday, August 03, 2014 11:20 AM
  • yes you got the point but the website i wan to host in the server and the database will be local cause the web have user inter face and just like normal web can be search by url.

    the free web hosting is just for testing i will put in on the live hosting .

    hope you all can help me up with this,i have been searching about 1 week plus.

    Thank You.

    Sunday, August 03, 2014 11:41 AM
  • Ok.  I understand now.  You want to remote into the SQL Server from the Hosting site.  The credentials in the connection string have to be correct.  You said the conneciton string works from a desktop.  Does it work from a desktop on a remote PC?  I suspect the issue isn't the connection string but an issue with windows allowing remote connections.  What windows operating system is on the SQL Server machine?  You have to allow remote connections. 

    jdweng

    Sunday, August 03, 2014 12:35 PM
  • Yes my desktop application can connect to sql server and i already config the sql server with fire wall.

    the web can connect to database but when i use url to see it keep popping out error.

    i change the connection string to this,

    <connectionStrings> <add name="ConnectionStringName" connectionString="Server=MYSERVERIP;Database=DATABASENAME;User ID=ID;Password=PASSWORD;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;" providerName="System.Data.SqlClient" /> </connectionStrings>

    but still cant work.

    the ip address i key in is the default gateway ip4v.

    Thank you.

    Sunday, August 03, 2014 1:13 PM
  • I asked if a remote machine running your desktop can connect to the SQL Server?  Can you ping your SQL machine from the Hosting Server?

    jdweng

    Sunday, August 03, 2014 2:00 PM
  • Hello,

    Have you tried Joel's suggestions of "allow remote connections" and "ping your SQL machine from the Hosting Server" as these are good to check for this issue.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

    Sunday, August 03, 2014 2:46 PM
    Moderator
  • yes my sql server can be remote.

    thank you^^

    Tuesday, August 05, 2014 2:24 PM
  • i use a software from Microsoft program to ping and remote can be done i can connect my database in local web debug but when i put it at web hosting cant connect.

    thank you

    Tuesday, August 05, 2014 2:28 PM
  • Your connection options arre inconsistent, but I don't think that is the cause of the issue

    Persist Security Info=True;User ID=userID;Password=Password"

    When you use Persisted Info you don't need ID and password it uses the windows credentials and gets password from a pasword server that is common between client and server PC's.  I bet your desktop won't work if you use a remote PC that isn't in the local domain.

    I still think the followng is the issue

    I suspect the issue isn't the connection string but an issue with windows allowing remote connections.  What windows operating system is on the SQL Server machine?  You have to allow remote connections.   You need a user


    jdweng

    • Marked as answer by CalebJohnny Wednesday, August 06, 2014 6:11 AM
    Tuesday, August 05, 2014 2:46 PM
  • You will need to use the IP address of your local PC in the connection string you use on the web server: SQL Server connection strings.

    That will be a problem if your PC is connected to the Internet via NAT. Your router may be able to do port mapping. However, you may get a different IP address on the Internet side of your router occassionally or even most times you switch on the router.

    It is generally a Bad Idea to expose an SQL server to the Internet because malware will attack it.

    --
    Andrew

    Tuesday, August 05, 2014 3:53 PM
  • ...continued, as I had to go elsewhere suddenly.

    What you could do, to avoid exposing your local SQL server to attacks, is set up IIS on it and use WCF or such to provide services to the web application. That way, you can rigorously filter requests. Make sure that you use parameterised SQL queries, and use SQL stored procedures as far as possible rather than allowing arbitrary queries.

    However, seeing as the website will probably have a fixed IP address, you may be better off running the database on the web server and using WCF or such on it, then using WCF to connect to the server from the desktop program. Also, you will not have to have your computer switched on all the time for the web site to work, and if your Internet connection fails it will not break the website.

    HTH,

    Andrew

    • Marked as answer by CalebJohnny Wednesday, August 06, 2014 6:11 AM
    Tuesday, August 05, 2014 8:01 PM
  • Thank you guys for helping me guess i need to do more research and testing for the web and software to connect together.

    I agree what you have say if use ip address is not safe others can just easy hack in.

    Thank you

    Wednesday, August 06, 2014 6:16 AM
  • Hey Andrew,

    I recently try to learn IIS but what i google all is about local database with local host but i cant find anything like local database and web will be at web hosting mind guard me through.

    Thank You.

    Johnny

    Tuesday, August 12, 2014 5:42 PM
  • I recently try to learn IIS but what i google all is about local database with local host but i cant find anything like local database and web will be at web hosting mind guard me through.

    There are some things you need to make the learning process easier. First, you should ideally have the version of Windows which corresponds to the server version of Windows at your hosting provider, e.g. Windows 7 goes with Windows Server 2008 R2. See IIS installation. That way, you can have the same version of IIS on your home PC (there will be some slight differences). You will want to use IIS: How to: Specify the Web Server for Web Projects in Visual Studio.

    You will be dealing with ASP.NET, so really the forums at forums.asp.net are the place to go for your initial investigations into this.

    There is quite a lot to learn: keep at it and you will be successful!

    Andrew

    Wednesday, August 13, 2014 6:30 PM