SQL Server 2008 Filestream Win32 error without a network cable! - sql-server

I have a SQL Server 2008 database utilizing Filestreaming and all works fine and dandy apart from under one very strange circumstance. If i have my database on, say a laptop, on a locally installed version of SQL Server 2008 and am connected to the network all works fine. If i unplug the network cable, after a while the SqlFileStream class fails to initialize with a Win32 exception (everything else about connecting to the database works fine). If i start fresh without a network cable it will not work with the same error. If i plug a network cable in even with no network connectivity it works... take it out, nothing.
I'm connecting to the filestream in the usual documented method
SqlFileStream fileStream = new SqlFileStream(path,
context,
FileAccess.ReadWrite,
FileOptions.SequentialScan,
0);
geting the path and context from a stored procedure which generates them in the following
SELECT Data.PathName(), GET_FILESTREAM_TRANSACTION_CONTEXT()
FROM dbo.DocumentFiles
WHERE [File_ID] = #FileId
I'm getting the following error when creating the SqlFileStream instance
Win32Exception occurred The network
location cannot be reached. For more
information about network
troubleshooting, see Windows help.
No inner exception.
I have tried so many things to resolve the issue with no luck. no one in google-land seems to have the same issue so obviously something silly I'm doing. If anyone can shed any light on this i would be most grateful.
James

Hmm. It looks like your network interface goes down when you unplug your cable. When it happens TCP/IP stack goes down as well since there's no more available interfaces left. I suggest you to to install the MS Loopback adapter, this article explains how to do it in Windows XP; it is easy to google about how to do it in other OSes. Do not forget to assign a static IP to it after installation, private address like 192.168.1.x would be sufficient. Since loopback adapter is a virtual one, it is in "Up" state all the time, even when you unplug your cable and it prevents Windows from shutting TCP stack down.

Related

Azure Function Database Connection

I have a Python package that I am able to run successfully on an Azure Data Science Virtual Machine. However, when I push it to Azure as a Function, I cannot successfully make a database connection. I was getting an error that the ODBC Driver 13 for SQL Server was not supported, so I changed the driver to ODBC Driver 17 for SQL Server and now I am NOT getting an error, but no data is being returned for a query that I know should return data.
Is there any other reason that data would not be returned? Firewall issues? do I need to add a binding? Do I need to separate out the connection string to feed each part (e.g., Driver, UID, PWD) into pyodbc.connect() separately? Right now I am feeding it in like this:
setting = os.environ("CONNECTIONSTRING")
conn = pyodbc.connect(setting)
This query works fine returning data when I run it on the VM using this code, just not as a Function.
(Note, this is different from my previous post regarding reading the Azure App Setting. That problem has been solved).
There are many parts where this could be breaking.
I'd suggest start by having a Profiler or Extended Events trace on your SQL Server to verify whether a connection is even being established. If not then you need to work through the the various points of connectivity to find out where it breaks. The identity, firewall, NSGs etc might all come into play here.
Once you see a connection then you can play with permissions to ensure that your query then returns your data.
Without a full picture of your infrastructure and settings it is hard to pin it down further.
Turns out it was not a database connectivity issue like I thought it was; it was a code error.

Labview - SSMS database communication... How to communicate between Labview and Microsoft SQL Server on separate devices?

I am attempting to set up a communication between Labview and Microsoft SQL Server, on two separate devices, in order to send and receive information about the database from both labview to SQL Server and SQL Server to labview. However, when I reach the "Data Link Properties" menu, I get the same "unable to log in" error upon attempting to log into the server. The server name comes up, however, an error occurs once I move on to select the database on that server. Is there any solution or tutorial to this problem that can allow me to successfully communicate back and forth from labview and smss on separate devices?
I've opened up various ports to allow a connection, even disabled the firewalls on both devices. The devices are connected via an Ethernet cable and I AM able to ping the devices to each other. However, in regards to being unable to log into the server in ssms, I have created new users, adjusted the login properties, tried changing permissions, but anything I try doesn't seem to solve my issue.
Can't really help much without seeing the error or some of the code of what you are trying to do.
That being said, if you go to the menu and select Help>Find Examples... and search for database, you should see a bunch of different things related to database connections. You may find the Database Connection.vi one helpful.
More info on the Database Connectivity Toolkit in LabVIEW can be found here
I see there can be one of the 2 issues
1) Inbound/Outbound port rules not set, Remote connection to server is not allowed.
2) If the server has multiple instances then you need to provide full host name of the instance you are trying to connect.
*Please refer to the below link to configure firewall rules.
https://learn.microsoft.com/en-us/sql/sql-server/install/configure-the-windows-firewall-to-allow-sql-server-access?view=sql-server-2017

Access dropping SQL connection

Not sure if this is the correct forum for this, but here goes.
Im looking for any suggestions as to what I can try to reslove this...
I have an Access 2003 front end (on each client) with SQL 2008 database. Ive went round each user and set up the odbc connection on each pc.
for most users its fine and been working well for a year, but for a few every now and then when running a query (either an update or a select when opening a form) the SQL connection seems to have been dropped and they cant go any further.
I cant think of any glaring difference between those who have it working and those who dont.
Any idea's where I should start with this?
thanks
I've had such cases before: Access frontend, SQL Server backend. On one or some of the customer's PCs, the connection suddenly drops (throwing some ODBC or SQL Server connection error). Happens randomly and rarely (e.g. once per hour/day/week), and the Access application needs to be restarted to continue working.
In all of these cases, one of the following was the culprit:
Broken network cable
Broken network card
Buggy network card driver
Unstable network protocol (yes, this one was in the old days of NetBIOS)
The thing is: Access is extremely sensitive to network errors. A simple glitch in the network, a few seconds of lost connectivity -- something which you won't even notice with other applications -- will cause an Access frontend application to lose its database connection and crash horribly. It's very frustrating, because the customer will say "I don't experience any network trouble with Word/Windows Explorer/etc., so my network is fine, and it's your application that's broken." It's not true. If Access experiences sporadic and unpredictabe network errors, it's usually really a network problem.
So, the first thing I'd do is to replace (a) the network card, (b) the network cable and (c) use another switch port for one of the machines experiencing problems. If the problems are gone on that machine, you know that one of these components was the faulty one.

Mirroring in SQL Server 2008

I'm trying to set up mirroring between two sql 2008 databases on different servers in my internal network, as a test run before doing the same thing with two live servers in different locations.
When I actually try and switch the mirroring on the target DB (with
ALTER DATABASE testdb SET PARTNER = N'TCP://myNetworkAddress:5022') I'm getting an error telling me that the server network address can not be reached or does not exist. A little research suggests this is a fairly unhelpful message that pops up due to a number of possible causes, some of which are not directly related to the server existing or otherwise.
So far I've checked and tried the following to solve this problem:
On the target server, I've verified that in SQL Configuration Manager that "Protocols for SQLEXPRESS" (my local installation is labelled SQLEXPRESS for some reason, even though querying SERVERPROPERTY('Edition') reveals that it's 64-bit Enterprise), and Client Protocols for SQL Native Client 10 all have TCP/IP enabled
I'm using a utility program called CurrPorts to verify that there is a TCP/IP port with the same number specified by the mirroring setup (5022) is open and listening on my machine. Netstat verifies that both machines are listening on this port.
I've run SELECT type_desc, port FROM sys.tcp_endpoints; and
SELECT state_desc, role FROM sys.database_mirroring_endpoints to ensure that everything is set up as it should be. The only thing that confused me was the "role" returns 1 .. not entirely sure what that means.
I've tried to prepare the DB correctly. I've taken backups of the database and the log file from the master DB and restored them on the target database with NORESTORE. I've tried turning mirroring on both while leaving them in the NORESTORE state and running an empty RESTORE ... neither seems to make much difference. Just as a test I also tried to mirror an inactive, nearly empty database that I created but that didn't work either.
I've verified that neither server is behind a firewall (they're both on the same network, although on different machines)
I've no idea where to turn next. I've seen these two troubleshooting help pages:
http://msdn.microsoft.com/en-us/library/ms189127.aspx
http://msdn.microsoft.com/en-us/library/aa337361.aspx
And as far as I can tell I've run through all the points to no avail.
One other thing I'm unsure of is the service accounts box in the wizard. For both databases I've been putting in our high-level access account name which should have full admin permissions on the database - I assumed this was the right thing to do.
I'm not sure where to turn next to try and troubleshoot this problem. Suggestions gratefully received.
Cheers,
Matt
I think that SQL Express can only act as a witness server with this SQL feature, you might get better mileage on ServerFault though.
Mike.
Your network settings might be OK. We got quite non-informative error messages in MS SQL - the problem might be an authorization issue and the server still will be saying "network address can not be reached".
By the way, how the authentication is performed? A MSSQL service (on server1) itself must be runned as a valid db user (on server2, and vice versa) in order to make the mirroring work.

Connecting to SQL 2005 from a windows mobile device

I am trying to write a simple application that runs on a Windows Mobile 6 device and can connect to a SQL 2005 server and read and write to the database. It is ok if it only connects to the SQL server while it is docked.
I have never worked with mobile devices, so I may be thinking about it incorrectly. I created a DataSet and a TableAdapter like I would with a regular desktop app, but when I run the application in the emulator, I get a SqlException when I try to open the connection on the TableAdapter.
Is there something obvious I'm missing? Do I need to explicitly tell the emulator to act like it is docked? Does it need to be configured to see that it is in the network? I can ping the SQL server in question from within the app so there should be some connectivity
Here's a good link for setting up your emulator to connect to a network:
http://www.xdevsoftware.com/blog/post/Enable-Network-Connection-Windows-Mobile-6-Emulator.aspx
psasik is being polite when he describes emulator network connections as "squirrelly". I've never gotten them to work successfully, but this is because I always have an actual physical device handy, which I always go back to at the first hint of emulator problems.
Thanks for the link! It was helpful, and I can confirm that I can connect to the network. Unfortunately, it still will not connect to the SQL server. I have distilled the code down to:
`
string connStr;
System.Data.SqlClient.SqlConnection myConn;
try
{
connStr = #"Server='<server name/IP>';Database=<database name>; User Id=sa; Password=<password>";
myConn = new System.Data.SqlClient.SqlConnection(connStr);
myConn.Open();
}
catch (System.Data.SqlClient.SqlException se)
{
MessageBox.Show(se.ToString());
}
`
This code throws an SQLException at the myConn.Open() with errorClass 20, number 17. The message is "SQL Server does not exist or access denied." The exact same code (copy/pasted) works perfectly in a winforms application. Am I doing everything correctly? Is it likely that the code is correct but that the emulator is causing my problems? Would it be worth asking the boss for a mobile device to try it on?

Resources