remote connection string from Webmatrix 3 to Microsoft SQL Server - c#

This seems like a really easy problem to solve, from what I can gather online, but I cannot get it to work for the life of me:
I am trying to help out my dad on his website. It is an ASP.NET based site using Microsoft SQL Server Management Server. The code was developed using Visual Studio, and is hosted with Microsoft's IIS, so, in essence, it is a completely Microsoft-based site.
So far, I've gotten a test site to essentially work on WebMatrix 3; however, I cannot figure out what I need to put into the connection strings in order to get WebMatrix's SQL system to connect to the production server.
I also tried to duplicate the databases by extracting the structure from the production databases and running the query on WebMatrix, but the program needed service pack 2 for MS SQL 2008, and that install is failing for reasons I don't know why.
Best case scenario is I connect to the production server's databases.
Currently, the connection strings have:
Data Source = (ComputerName)\SQLEXPRESS
Initial Catalog = (db)
Persist Security Info = true
User ID = (uid)
Password = (password)
ProviderName= System.Data.SqlClient
So, to clarify,
Web Matrix is installed on my desktop computer, and the website is the code itself. The production site is the website code installed and running on a server somewhere I don't know where, while the test site is a copy of the website loaded onto webmatrix.
There is one working copy of the database, and it is on the production server.
I am trying to construct a connection string within WebMatrix that will connect to the server, through the proper port, and login to the database there to retrieve the data necessary to construct the site so that I can edit the code and test it.
So my question, in particular, is how does one accomplish this when there does not seem to be a slot to indicate a port in the WebMatrix connection wizard?

Webmatrix supplies a wizard to create a connection with a SQL Server. In the Databases workspace you must select Connections > New > Sql Server Connection an input your configuration data into the form.
Anyway the resulting connection string in the Web.config file should be like this:
<connectionStrings>
<add connectionString="Server=(ComputerName)\SQLEXPRESS;Database=(db);Uid=(uid);Pwd=(password)"
name="MailingLists" providerName="System.Data.SqlClient" />
</connectionStrings>

OK, my apologies; I have figured out how this works.
In the connection wizard, you can treat the "Server" box as if it were the "Data Source" option specified in a regular connection string. Then, you can add a comma and the port at which the SQL Server is set to listen.
However, now I am dealing with the problem where the host machine is actively refusing my connection.

Related

Application can't connect to copy of SQL Server database on other computer

I have created a C# application that connects to a SQL Server database which I created in SQL Server 2014 Management Studio. I need to send my app, my database, and instructions to get them working to someone for assessment.
My application connects perfectly on my computer with the connection string
Data Source=(local);Initial Catalog=ReportsDB;Integrated Security=True
However I am testing it on another computer and it will not connect with that same string.
I have installed SQL Server 2014 Express on that computer, and restored the database so it is identical to my main computer.
Any advice on how to make this work, or alternatively make it portable enough to submit?
The problem I had was that I assumed that connection strings were the same (apart from computer name) between SQLServer and SQLExpress however they are not.
My solution was rather hacky- I found the SQLExpress Connection String using VS on my second computer, replaced the computer name with the (local) keyword and then made an option in my application to switch between the default SQLExpress or SQLServer connection string so the user might change it manually. I also included an option to allow them to completely modify the connection string if neither default works. This is far from the most elegant solution, but with my limited understanding, it is passable to get the system working on a new computer.

How to deploy a windows forms database application

I am developing a windows forms application that needs to communicate with the SQL Server. I'm facing a problem when I deploy the application once the connection string is trying to connect to an invalid address.
I've already searched a lot and I found out the connection string must have the |DataDirectory| directive. Now the .mdf file is located on the directory C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA. Actually the connection string is:connectionString="Server=.\SQLExpress;AttachDbFilename=|DataDirectory|PDVDatabase.mdf;Database=PDVDATABASE;Trusted_Connection=Yes;"
The only way my app connects to the database is by the Server Explorer (I'm using Visual Studio 2013) where I get the static connection string of the .mdf file I set up in the app.config, but that way won't work after the deployment.
My question is: How do I do to connect my app after the deployment in order to communicate with the .mdf file? (I'm using a setup project for deployment). What's can be wrong?
Thanks.
A lot of things need to be addressed
1) You need a copy of your MDF and LDF files to be distributed with your app
2) You need to know if your user has Sql Server installed in its internal LAN or its PC
If the previous condition is true then
3.1) You need to attach your copy to the end user Sql Server Instance
3.2) You need to change your connection string to point to the end user Sql Server Instance
else
4.1) You need to distribute and install LOCALDB
4.1) You need to prepare the connection string for LOCALDB
Some links to help you in this task
To Attach and Detach a database information
For LOCALDB information
Connectionstring for LocalDb
Find Sql Server Instances Across your network
You should put the connection string into App.config file of your application. There is a section meant for that in the config file.
<connectionStrings>
<add name="Connection String name" connectionString="..."/>
</connectionStrings>
That gives you a flexibility to change the config file after during the deployment of your application to make sure that the connection string points at the database in the user environment.
Later you can fetch the connection string in your C# code from the System.Configuration.ConfigurationManager.ConnectionStrings collection.
Read on the internet on how to write different connection strings, ex here: http://www.connectionstrings.com/ and you should be able to write a correct connection string to the database.
Maybe your troubles are caused by incorrect users and permissions setup in the database. You have to be sure, that the user, that is using your application after deployment, has right to connect and work on the database

Connect to an ASP.NET SQL express db with another C# Project

I'm currently working on a project that has a front end ASP.NET website where users will submit "orders". I then need to access a specific table in this database with another C# windows form application that interacts with multiple Serial Ports. (I'm not married to this idea, so if you think it's a better idea to have one website for both functions, i'm all ears)
Anyway, this question is regarding the ability to have two connection strings (one from ASP.NET, and the other from a local program. - Both of which will be run on the same computer)
On the C# end, i have a connection string of:
"AttachDbFilename=C:\\Users\\Jordan\\Documents\\Visual Studio 2012\\WebSites\\WebSite1\\App_Data\\MyxoData.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True;"
With this configuration, when one project is active, the other cannot access the database.
Cannot open user default database. Login failed. Login failed for user 'CMYK-164\Jordan'.
I have a feeling this is because I am using Integrated Security=true in my connection string and "User Instance=True" specifically only allows one user on a computer to log into a DB at a time...but I can't find anything that backs up my theory...or has a way around the problem.
Any suggestions would be much appreciated!
EDIT
The connection strings are not an issue. Both applications work perfectly when the other isn't active. The issue here is establishing two concurrent connections to one database, from two different C# applications.
Building on what Rafeal's response; you need to upgrade to SQL Server Express.
SQL Server Express LocalDB is a stripped-down version with a lot of limitations; one being that it does not support concurrent connections. See the link below - the part explaining the concurrent connection limitation can be found in the last sentence of the Permissions section.
http://technet.microsoft.com/en-us/library/hh510202.aspx
You can install SQL Server Express here:
http://www.microsoft.com/en-us/server-cloud/Products/sql-server-editions/sql-server-express.aspx#fbid=xWTelsiKWFm
And in Visual Studio you can use the Database Explorer to create a Data Connection to the new database to create your tables and any stored procedures you need.
If you are not familiar with .Net and SQL Server, you can connect to the SQL Server Express database easily by using the System.Data.SqlClient namespace. Since it's designed for SQL Server products, it is supposedly more efficient than using ADO.Net or other data providers. And, at least, I have found it to be quick and easy to use. For example, since the provider is explicit, you don't need to specify a provider in the connection string, resulting in a shorter string. For more information on the connection string, see this page:
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectionstring(v=vs.110).aspx
And you can find C# and VB examples of opening a connection at the bottom of this page:
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.aspx

Login fails when try to connect by app but not by the Management Studio

I have a WebSite that just don't connect to database. Both are on my local machine.
Using the same parameters (Host, User ID, Pwd and Database) I can connect with the MS SQL Server Management Studio.
What can by my problem??
Here goes the two ConnectionStrings I'm trying to use:
Data Source=VIVID-28\MSSQLSERVER1;Initial Catalog=DicionarioDados;Persist Security Info=True;User ID=VIVID-28\Development;Password=*******
Server=VIVID-28\MSSQLSERVER1;Database=DicionarioDados;Integrated Security=SSPI;User ID=VIVID-28\Development;Password=*******
VIVID-28 Is the name of my machine.
MSSQLSERVER1 Is the Instance.
Try removing the "Integrated Security=SSPI" section. That means that it uses Windows Authentication and hence will ignore the user name and password you are passing in your connection string.
To test your connection you can try using VS server explorer and by adding connection to your sql server database you can test whether connection can be made with given parameters or not. ones you able to connect you can select the connection and go to properties and copy the connection string and past it as your application connection string.
There can be many reasons of this , see the following similar question and see the links I have given in the post, follow the steps.
Why I am not able to connect to remote SQL Server from asp.net website whereas it is connecting from SQL Server Management Studio
Do you work with multiple SQL Servers?
Are you absolutely sure that the SQL Management studio is connecting to the same sql server / instance as your code? If you have a production and development server, you may have created the user on your production server, but not development, or the password may be incorrect.
Try resetting the password on your development server and see where that takes you. (:

How to connect a hosted Web Application with a local database?

I have hosted a web application(Application is in Asp.Net with C# language and Sql server database). Now i want to store data in my local database from my hosted web application.How will be the database connection string...any addition changes in Sql Server..?Please explain..Any reply will be appreciated..
DeEP
from .NET 2 upwards the connection string can be stored in a specific node of the web.config file and not in appSettings as it was done before.
I am not sure about your question because if you try to access a database server located outside the network where you have deployed your ASP.NET application (so the hosting provider's internal network), it won't probably work, even in case your SQL Server is publicly available and open for connections from outside (which is bad, really, really bad...), it would also depend on the hosting company network settings.
How did you connect to the SQL Server during development and for debugging within the development machine?
There are info on how to connect to a SQL Server with a connection string in the web.config here: Using connection strings from web.config in ASP.NET v2.0 but not sure this solves your issue.
Sounds like you need to speak to your network administrator - I'd guess that your firewall will probably be set up stop any attempt to access it from outside of your network.
If your hosting company allow it, you maybe able to set up a VPN between the web server and your local database but this would be a lot of hassle.

Categories