I've been doing a little work with SQL Server and C# and every time I run the darn thing the connection times out unless I start services.msc and manually restart the service (SQL Browser Service). It's already set to automatic, does anyone know why it would do this? I'm not an advanced programmer, more of an intermediate one. Once I do restart this service it works fine as long as I keep using it. If I stop using it for more than 30 minutes I have to restart it again.
Have you checked the SQl Server Log and the windows event log?
Can you supply some more info., such as the C# code you are using to open/close the connection, the connection string etc.
Is autoclose kicking in?
Defaults to ON for SQL 2005 Express version, but it could have been set for other versions. The database should open automatically though...
Is it a query from the app that times out?
Or simply trying to connect to the server to run, say, SELECT ##SERVERNAME?
Can you connect to the SQL Server by name through SSMS without fiddling with the Browser service (I'm not even sure this really requires the Browser service depending on how you connect)? i.e. does it appear to be running fine except when your program causes it to crash? And once you've restarted it does it work fine repeatedly or do you have to keep restarting it as you use your program?
What version of SQL Server 2005 (and what service pack level) are you using?
Related
I have a SQL Server with two databases, a production database and a development database. The .net 2.0 website hitting the production database with manual SqlConnection code is working fine. The other database is being hit from a newer ASP.NET MVC app using Entity Framework 6.2 and is getting timeout issues. The timeout takes 30 seconds the first time, but the page comes back almost instantaneously on subsequent refreshes. Both websites are on the same box as the database, so are only using "localhost" to connect. They are using SQL Server user logins, not Windows authentication.
I copied the .edmx and .tt files into a .net console app and that app has no problem hitting the database with the exact same linq query and pulling the same data that is failing.
I then created a new web site and copied just that same code into an aspx page. It fails the first time with a timeout, and then works on subsequent attempts (and a week ago, the main dev site was doing the same thing).
I separated the dev database from the SQL Server 2008 R2 server and attached it to a newly installed instance of SQL Server Express on a different port, and get the same results.
The web server is windows server 2008 standard 32-bit. I copied both websites and the console application to a new box (I thought was 2016, but it turns out it is 2008 standard 64-bit) and get the same results.
The dev site was working up until a couple of months ago. The client was using local user accounts for everything, but had a domain and wanted to do testing with windows authentication for an old vb app that hits the same database, and I had started migrating testing accounts to the domain. When the client tried to later, for an unrelated reason, change his password, we discovered that he was already using a domain account, but that his laptop could not connect to the domain. We found several other computers that could not connect, even though the machines I had connected to the domain during my testing were working fine. An outside network "friend" was brought in to figure out what was going on. At that point, I lost all track of what was actually done. I know that different network and domain configurations were tried and didn't fix the domain issues, but I don't know what. However, the production site was never rendered inoperative.
I have no idea what is going on. Does anyone else?
Oh, and in case it was a provider issue, I've also tried manual connection using OleDbconnection from the web app, and it also fails with the Timeout issue.
Update:
I spun up a new DataCenter 2016 box, installed IIS and .net on it and copied the website to that box. It has no problems hitting the database and pulling the data from the other server.
I know patches and such were updated on the original box while the domain and network were being manipulated, but I don't know how far behind they were. I suspect that some patch changed some default or inherited .net configuration options or something. I did do a "repair" on the .net installation, and that didn't make a difference. However, with the production site working fine, I'm not currently willing to uninstall .net or anything else. I'm afraid I would risk pushing this same error into the production site and the client would be screwed.
It seems that for some reason, the timeout period elapsed while attempting to consume the pre-login handshake acknowledgement.
Try increasing the connect timeout property in your connection string to 60 or more. Default is 15 (in seconds).
Example: Data Source=(LocalDB)\v11.0;Integrated Security=True;Connect Timeout=30
I have one problem that's causing more problems.
Let me explain what's going on:
For the past week, wanted to learn ASP.NET MVC and develop an app.
To get my machine ready, installed:
Visual Studio Enterprise 2017 32/64-bit (Multilanguage)
SQL Server 2016 Enterprise With Service Pack 1 64-bit (English)
So, after that, I thought to be good to go.
This is the app I'm using to do the learning: APP.
Then, once I open in Visual Studio, this is what happens first:
Didn't really understand this message. but my thought remained: how can I open using SQL Server 2016?
This "problem" quickly vanished with:
Ok, let's still try to do a build and see what goes on:
Cool, I'm able to see the app.
Well, now that I'm in a "lucky day", let's test to register:
This last error has to do with the protocols selected for the server.
It has to do with MS SQL Server configuration. Which means, I may need to install additional ODBC drivers for MS SQL.
How can I fix this and be able to register?
Note: If there's any info you might find important in order to understand how to help me with this problem, let me know. This because I'm a noob in the field, just getting started.
Here is the course I've been following.
You need to create a database in your SQL Server 2016 and then update your connection string to use that database.
Your connection string should look like
Server={server name},1433;Database=tiagoleft.music_shop.dbo;User ID={user id};Password={your_password_here};Trusted_Connection=False;Encrypt=True;Connection Timeout=30;
Note: while installing, if you configured only windows authentication, then you have to update the connection string to use windows authentication. For that to work, replace the user id and password from the above string with
Integrated Security=True
I have a windows service written in c#, which when running connects to a sql server database.
When the service first starts it connects to the database to obtain various information for the service to run.
The service is set to automatically start if the server it is installed on is restarted.
If the service starts before the sql server service has started. My service when started obviously has an initial execption error when trying to connect to the database.
To combat this issue, if the exception occurs I have added a short delay before try to connect to the database again, I continue this n amount of times until it connects
My question is, is there any alternative solutions to what I am doing already
thanks
Make your service dependent on SQL Server, done using ‘sc’.
Using a poll, as you're doing right now is fie, and you'll still need it if your service starts after SQL Server because you can never be sure SQL Server has fully started then.
I have Visual Studio 2010, Sql Server 2008, Sql Management Studio and pretty much everything installed.
I can create a local database with Sql Server Compact and Windows authentication just fine. Now I'm a little perplexed, because I still have no idea how all of this works. I didn't use any connection strings, passwords or anything. While coding, I can clearly see that the DataContext class in C# when using LINQ to SQL needs a connection string. How can I test this on my own pc? Is it unreasonable that I want to test this kind of stuff throughly while not currently having hosted services on the Internet yet? And often times, I don't have so much access to the server when using shared hosting, so I can't learn very fast and not fully.
When trying to connect to different services through SQL management studio and Windows authentication and my local pc, I just get a connection error.
Error Number: 2
Severity: 20
State: 0
I don't think that the database engine is the appropiate service to connect to anyway based on what I read, I just thought that you would like to know what I tried.
I checked, and sqlservr.exe is running in the processes in the task manager. Also SQL Server VSS writer.
Basically, I would like to learn how SQl Server databases work. The books, wikipedia and msdn on this topic just enumerate a lot of cryptic services like the database engine, analytical services etc...
I can't find any basic information on how to actally create, connect and program with a real database on my own pc. I'm not even sure whether I'm supposed to work like this?
I read that Sql server compact only supports databases up to 2mb.
Is it not possible for me to work with "the real thing" on my local pc?
I'm very very new to all this, and I'm not getting anywhere with databases...
Thanks for any help!
See: no option for a full sql database.
Server seems to run, but why does it say Server express? I'm sure I have the full one.
Installing Visual Studio generally installs a SQL Server instance on your local machine.
It is acceptable to work with "the real thing" on localhost, since when changing server, only the connection string has to change.
You will have to install the right version of SQL Server Management Studio Express (SSMSE) for your version of SQL Server so that you can start it, authenticate and work with SQL Server.
You may also connect to your SQL Server using the Server Explorer windows from within Visual Studio. Menu View|Server Explorer, or else [CTRL]+[W], [L] to view it. Then, you may connect to a data server from this window using the connection buttons on top of it.
Click View|Server Explorer, to view it;
Server Explorer, click "Connect" button located on top;
Choose a data source dialog, Data Source, click Microsoft SQL Server;
Data Provider, select .NET Framework Data Provider for SQL Server, click [Continue];
Add a connection dialog, Server name, select the server you want to connect to (your [local machine name]\SQLEXPRESS might appear, or something alike);
Server connection, choose Windows Authentication;
Database connection, select the database you want to connect to, and click [Test Connection];
If the test succeeds, click [OK], and you're done!
Disclaimer
The names of menus or window title may differ a bit, but you should get it done anyway. That is because I have off my head translated from French to English what it actually says in French, working with a French Visual Studio.
EDIT #1
After having taken an eye out your screenshot, I would simply say that you only have to select Database Engine to connect to your SQL Server instance, by selecting the right server on which you wish to work.
The full database option you're looking for is Database Engine which designates a full SQL Server.
The others are for the different services such as:
SQL Server Reporting Services (SSRS);
SQL Server Integration Services (SSIS);
SQL Server Analysis Services (SSAS).
Feel free to ask further assistance as needed. =)
How can I make a program use a SQL Server database, and have that program work on whatever computer it's installed on.
If you've been following my string of questions today, you'd know that I'm making an open source and free Help Desk suite for small and medium businesses.
The client application.
The client application is a Windows Forms app. On installation and first launch on every client machine, it'll ask for the address of the main Help Desk server.
The server.
Here I plan to handle all incoming help requests, show them to the IT guys, and provide WCF services for the Client application to consume.
My dilemma lies in that, I know how to make the program run on my local machine; but I'm really stumped on how to make this work for everyone who wants to download and install the server bit on their Windows Server.
Would I have to make an SQL Script and have it run on the MS SQL server when a user wants to install the 'server' application?
Many thanks to all for your valuable time and effort to teach me. It's really really appreciated. :)
Edit:
To clarify, each business will have their server completely separate from me. I will have no access whatsoever to them nor will they be in any way connected to me. (I don't know why I should clarify this :P )
So, assuming the have ABSOLUTELY NO DATABASE SERVER installed; what can I do?
Ok, part of the answer, dealing with the SQL Server Database (and frankly SQL Server Express will take you a long way - 4Gb of data) and the server install elements.
Firstly make installation of the SQL an SEP, make it a pre-requisite possibly tweak your installers to test (challenging) but substantially point them at the links to SQL Server express and let them get on with it).
Secondly separate installers, as suggested, for your client and your server elements.
Finally, how to build the database - I'd suggest using code to create and maintain (update) the schema i.e. once you have a connection to a server you can run code that calls DDL that does what is necessary (something like suggested here: How to create "embedded" SQL 2008 database file if it doesn't exist?)
A question - are you intending all communications from the clients to go through you WCF service?
Your install application should:
Obtain a SQL Server name, a username (with apprpriate rights to create a database) and password.
Either run SQL scripts using the locally installed command line tool or from code using SMO (for instance), against the user supplied server with the supplied credentials.
BTW, Before you expend effort writing an open-source help desk, have you checked what is already available? Also, Open Source Helpdesk
It is not so straightforward to deploy a client/server solution with an automatic installation.
You probably would then be better off to deploy your server installation together with a database engine and a skeleton database already setup according to your wishes. This is to avoid tampering too much with the existing server - who knows whats on it.
Also you say you want to install WCF services, well this would probably mean installing them on a customer server, in theory this shouldn't be a problem however in reality it could be, depending on what is previously on the server.
Do you want a single SQL Server instance running on your machine, or one on each of your customers' servers? If it's the latter, you'll want to install a SQL Server instance - anything from the (free, but limited and not open-source) SQL Server Express to a more expensive SKU - on each server. You can include this step in your server installation package; MSI installs make it very easy to bundle a MSSQL install.
Then you'll need to drop a schema, and maybe data, on the instance. You could do this as a step in your installer, or as part of your application setup process. It possible that a SQL Server instance, or more than one, might already be installed on the server, and your post-install step should allow the user to specify which instance on which to install your pieces.
Then, include a database configuration piece in your client application. Ask the user - or take from a configuration file at client install time, to allow for unattended or unprompted client installs - server connection details, like server name and authentication information.
A word on authentication - since you appear to be building Windows-based tools, use Windows integrated (domain-managed) authentication if at all possible. Don't get in the business of storing logins, but instead rely on the existing domain to manage logins. A good strategy is to use active directory groups to manage access. Grant access to a particular group in SQL Server, and defer group membership to Active Directory itself. If you can't gain the access necessary to do this, then grant permissions to AD user accounts themselves. Avoid creating SQL Server logins, the use of which open the door to some possible security problems.
I understand what you are trying to do. If I were you, I'd do the following:
Provide 2 downloads - 1 for client and 1 for server.
Forget about MS SQL Server and perhaps go with MySQL, since it really is open source. You could probably get away with using MS SQL Server Express Edition, but if your data set gets gigantic large (which is common with help desk databases), you'd be stuck.
As other people pointed out, on very first run (or at setup time), I'd have the client app locate the server.