Unable to connect to Database Engine or Server - sql

I am making a website for my friends. Here I have made a sign up page and using 3-tier architecture in .Net framework.
For database I am using sql server management 2008 R2.
On filling up the details in the sign up page I get an error. I am unable to understand whether I am unable to connect database or server properly.
What authentication I should use? Windows or SQL server Authentication and what has to be put up in web.config file.
Here are the screen shots.
My connectionString in DataLayerClass :
string strQuery = ConfigurationManager.AppSettings["djconnect"].ToString();
djconnect is the key that I am using in the app setting tag.

Pass connection string directly into datalayerclass using sql connection instead of passing it to web config.

Related

Publishing to live, changing localdb to SQL

I have created an ASP.NET MVC 3 application locally and now I'm wanting to publish it to windows azure server (which is all set up fine within my account) so that it is accessible by anyone.
However I'm having issues as the database used in the application and the connection strings in web.config are localdb.
How do I go about changing localdb to SQL database so that I can host the website live properly?
Do I just need to change the connection strings or is there further configuration required on the server or in the application?
Just change the connection string from localdb to SQL Server.

Entity Exception : the underlying provider failed to open with Timeout expired

OK, I'm stumped. I am trying to create a .NET Winforms app to talk to a database via Entity Framework. I originally created a ASP.NET MVC3 app (with a seperate DAL layer) that can talk to the database after initially failing. SO the first time that it tries to open the connection, it times out. If I then hit F5 in the browser, it connects fine!
I referenced this DAL in my Winforms app.
I can connect to the database via SQL Auth in SQL Management Studio fine.
I can create the ADO.NET Data classes in VS2010 (it connects, gets the tables and stores the connection string in the app.config).
However, once I run the Winforms app, I am unable to connect. I get the mentioned exception with an InnerException of "Timeout expired."
I copied the connection string from the web.config to the app.config.
The SQL database is hosted on my Windows Home Server called SERVER. I am in a Workgroup (no Domain). I uses SERVER\SQLEXPRESS in Management Studio and VS to successfully connect to it.
Things I've tried:
Disable the firewall on the client machine.
Enabled DTC on the server and added msdtc.exe to the exclusion list on the server.
Made sure Named Pipes in enabled on the SQL server instance.
Tried different SQL users.
Tried different ways of constructing the connection in C#.
Generated a new ADO.NET Data class local to my WinForms project (not referencing the DAL). VS connects fine, reads the tables, generates the code. But the running app causes a "Timeout Expired" SqlException.
So running the app is unsuccessful in connecting. When I watch the app in ProcessExplorer I can see an entry in the TCP window when it tries to Connect on remote port 4845 with a SYN_SENT message. Not sure if that's right.
I've google'd and bing'd this for the last few days, I've read all the articles and replies here on Stackoverflow that mention this exception, but I have hit a wall.
This is the ConnectionString that VS generated after reading the DB:
<add name="LLDBEntities" connectionString="metadata=res://*/LLDB.csdl|res://*/LLDB.ssdl|res://*/LLDB.msl;provider=System.Data.SqlClient;provider connection string="data source=SERVER\SQLEXPRESS;initial catalog=LLDB;persist security info=True;user id=sa;password=sapwd;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
Any help appreciated, even any hints on how to figure out what's happening.
Your connection string looks more like a connection string to an SQL Server, rather than SQL Express.
Have a look at this for a connection string to SQL Express: SQL Server Express connection string for Entity Framework Code First
Ok, solved.
I noticed that it would actually connect on the second attempt with the same app and connection. At that point I found this link: http://kromey.us/2011/06/microsoft-sql-server-2008-times-out-on-first-connection-attempt-447.html
So I opened the firewall port listed under IPAll Dynamic Port in SQL Server Configuration Manager on the TCP/IP Properties for the instance and now it all works fine. I still don't know why it would get through on the second attempt....

Running into an SQL Error with an MVC Application deployed on IIS

So I am new to working on web projects in general. I am working on an MVC application in Visual Studio 2008. I have generated an SQL database within VS, and I have deployed my application on IIS. However when I try to do anything in the application which will spark an SQL query, I get the following error:
"Failed to generate a user instance of SQL Server due to failure in retrieving the user's local application data path. Please make sure the user has a local user profile on the computer. The connection will be closed."
I have hit google on this problem, and people have suggested a number of solutions but I am unsure how many of them are relevant to me doing this when I'm doing this in VS2008,. I have tried a few simple things suggested like setting the trust level to full, and setting the Load User Profile to true in IIS, but no luck yet.
What edition of SQL are you running where you deployed the application to? If it is not SQL Express, you will need to remove "User Instance=True" from the connection string.

Can't establish SQL Server connection from VS 2008

I am sorry if this sounds like a silly question, but I have googled for a while for a solution and no success. I am trying to establish a connection from VS 2008 to SQL Server. I am trying to use an user that my web application has been successfuly using to access the database from in its connection string. But when doing it from VS 2008, it tells me "Login failed for use 'xxxxxx'". I am currently in the "Add Connection" window. I have chosen the datasource and server name, fulfilled username and password for SQL Server Authentication. Do I have to set specific permissions for this user? Do I need to allow a VS 2008 user in SQL Server? Thanks.
I have found the solution for this problem. My Visual Studio would pull automatically something like MACHINENAME\SQLEXPRESS. As it was pulled automatically, I did not bother taking a closer look at it. I finally realized the connection string that worked for me in my other application was .\SQLESXPRESS. When I entered it in Visual Studio, it did work. Thank you all for the help.
Do you have SQL Server Management Studio Express Installed? if so try connecting as the same user through that interface. This will isolate your problem a bit.
With Visual Studio, you're connecting through a "remote" connection, even though they're on the same machine. With Server Management Studio, you're connecting through a named pipe probably. You need to change the SQL configuration so that it allows remote connections. Here are instructions for how to do it.
You can test your SQL connection by connecting using LINQPad, Often find this solves problems with connections to new SQL Server instances at my workplace.
http://www.linqpad.net/
Are you trying to specify the username and password to connect with in the connection string - ALA:
Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;
This actually uses SQL Authentication, not Integrated (Windows) authentication. What you might be looking for is this:
Data Source=myServerAddress;Initial Catalog=myDataBase;Trusted_Connection=True;
This would log into the database as the use running Visual Studio. Notice that the username/password aren't specified here - it uses the current Windows identity - in your case, that's the user running Visual Studio.

SQL XML Bulk Loader - Error connecting

I'm using the sqlxmlbulkloadlib to perform an xml bulk load. When integrated security=SSPI, the process completes fine inside a workflow hosted on my local machine in a wcf service. However, when that workflow is hosted on our server and kicked off from a service reference on an aspx page, the bulkloader produces an error connecting to the data source. I have tried using sql server authentication instead, but that fails even on my local machine with the same error connecting to data source.
My connection string looks like:
"provider=SQLOLEDB;data source=Myserver;database=Mydb;User ID=Myuser;Password=Mypassword"
Ok, so after creating the sql account for the bulkloader, the policy required that I change the password. Didn't catch that till I tried logging in with the account in management studio.
I am curious, though, what I would have to do differently for integrated security to work from the production server.