|
This is the error message :
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 – Error Locating Server/Instance Specified) "
The server name and database name on that connection string are correct.
|
|
|
|
|
Even though the server name is correct, check that the instance name is correct. So to repeat the checklist
- is the server using named instance? If it is, use the format server=computer\instancename
- check that the firewall isn't blocking the communication.
- since you're using trusted security, check that your credentials have access to the SQL Server.
- and of course that the target SQL Server is running.
- check that TCP/IP protocol is enabled
Also there are certain situations when the communication cannot be established if the server is a cluster unless you specify the port. If you have a clustered SQL server you can try using TCP/IP address along with the port name. But as said, this applies only to certain specific situations.
|
|
|
|
|
Reading your comments , I think that the only problem that may be instance name.
But as I sad before , I want to do this programmatically.
So , is there a way that when my program run for the first time , to detect if is a Sql server or Sql server express.
If is sql server express , to detect the instance and to make the necessary changes to app.config file.
|
|
|
|
|
The instance name isn't related to the edition of SQL server. So Express edition instance can have any name. It's up to the person who has installed the SQL Server, what he/she has decided to give in the name definition.
Basically you find the names of the instances by communicating with SQLBrowser service on the database server. This service (when running) provides information about accessible SQL Server instances on the server. You can try what results you get with SqlDataSourceEnumerator.GetDataSources [^]
|
|
|
|
|
Hello !
On sql server 2008R2 , I have 2 fields in database :
One is VarChar (MAX) and the other is VARBINARY (Max)
I have a large string that when is saved to VarChar(MAX) field , the size is 250 bytes.
Now , using a compression library , I have compressed the string into an array of bytes , and after I have save to VARBINARY(MAX). The size of this field is 252 bytes.
What may be the problem ?
Thank you !
modified 11-Aug-15 11:31am.
|
|
|
|
|
No problem. It is just that after compression, and the addition of the control characters, the resulting data happens to be longer than the original. In general compression does not work well for small amounts of data.
|
|
|
|
|
yes , but if I have a file when I put this string , and after I compress the file , the compressed file size is less than the original file.
|
|
|
|
|
So your library uses a different compression system. Of course there may be a completely different answer, but from the information you have provided it is not possible to guess.
|
|
|
|
|
|
satc wrote: I have a large string that when is saved to VarChar(MAX) field , the size is 250 bytes.
250 bytes isn't a large string; varchar(max) can store up to 4,294,967,296 characters.
Compression typically works best on data with lots of repetitions. If every character of your string is a different character, the compressed data will always be larger than the input. If your string was just the same character repeated 250 times, the compressed data would be much smaller.
There's no need for a third-party library to compress strings in .NET - the System.IO.Compression namespace will do the job for you:
http://stackoverflow.com/a/2118959/124386[^]
public static byte[] CompressString(string str)
{
using (var output = new MemoryStream())
using (var gzip = new DeflateStream(output, CompressionMode.Compress))
using (var writer = new StreamWriter(gzip, System.Text.Encoding.UTF8))
{
writer.Write(str);
return output.ToArray();
}
}
public static string DecompressString(byte[] input)
{
using (var inputStream = new MemoryStream(input))
using (var gzip = new DeflateStream(inputStream, CompressionMode.Decompress))
using (var reader = new StreamReader(gzip, System.Text.Encoding.UTF8))
{
return reader.ReadToEnd();
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Yes , I know that 250 bytes is not a large string. But I have just tested with this string.
On this string the are a lot's of characters that repeats.
The library that I mention is based on the Net compression library but has some more functions. So the result is the same.
Why the compressed string has a larger size ?
|
|
|
|
|
Is the library you're using compressing the string, or creating a zip file? The overhead of a zip file would likely outweigh the benefits for such a small string.
Have you tried compressing your string using just the built-in methods?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
The library can create a zip file and also can compress a string. In this case I've used the library to compress the string.
|
|
|
|
|
But have you tried the built-in methods to see if there's any difference in the output size?
Can you post the string you're trying to compress?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Using your function posted before :
public static byte[] CompressString(string str)
{
using (var output = new MemoryStream())
using (var gzip = new DeflateStream(output, CompressionMode.Compress))
using (var writer = new StreamWriter(gzip, System.Text.Encoding.UTF8))
{
writer.Write(str);
return output.ToArray();
}
}
I always get a 0 length array.
Is there any error to this function ?
I have tried with different strings , and always I get a 0 length array.
Thank you !
|
|
|
|
|
Sorry, it looks like the DeflateStream doesn't flush properly until you call Dispose . Try changing the function to:
public static byte[] CompressString(string str)
{
using (var output = new MemoryStream())
{
using (var gzip = new DeflateStream(output, CompressionMode.Compress))
using (var writer = new StreamWriter(gzip, System.Text.Encoding.UTF8))
{
writer.Write(str);
}
return output.ToArray();
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hello my friends ! Sorry for this simple question that I post here.
Well, I need to update data in one Reoport Viewer. The problem is that its impossible. The only way that I found was just close the form and open it again. There is one code that I can use to update the report? One simple command or code line, if its possible? Thank you everybody, from Brasil !
|
|
|
|
|
Did you try the RefreshReport method[^]?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi, Richard !
Yes, I tried this and the Update method too. But, not work.
Thanks!
Lárimer
|
|
|
|
|
I'm using Entity Framework 6 and vb.net 2013 and DBContext.
I have a case when i use reflection to return for an object ( of whatever entity ) , property names and current values :
Dim values = obj.GetType.GetProperties.Where(Function(t2) t2.PropertyType.IsValueType).Select((Function(t3) New With { _
.property = t3.Name, _
.value = t3.GetValue(obj, Nothing) _
})).ToDictionary(Function(x) x.property, Function(y) y.value)
This code is working without problems , but instead of current values that this expression return ( on .value=...) , I need to get the original values for each property.
What changes should I make on my expression ?
Thank you !
|
|
|
|
|
Properties do not contain other values then the current ones.
You may want to try to get these values either sooner, or from a different source.
Read Richards answer
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
modified 10-Aug-15 11:52am.
|
|
|
|
|
Each entry in Entity Framework contains the Original value too.
|
|
|
|
|
So I learned; I was assuming reflection and the PropInfo class
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
You're looking for the DbContext.Entry method[^]:
Dim entry As DbEnttiyEntry(Of YourEntityType) = yourContext.Entry(yourEntity)
Dim currentValues As DbPropertyValues = entry.CurrentValues
Dim originalValues As DbPropertyValues = entry.OriginalValues
Dim databaseValues As DbPropertyValues = entry.GetDatabaseValues()
For Each propertyName As String In currentValues.PropertyNames
Dim current As Object = currentValues(propertyName)
Dim original As Object = originalValues(propertyName)
Dim database As Object = databaseValues(propertyName)
Next
Dim prop As DbPropertyEntry = entry.Property("PropertyName")
Dim current As Object = prop.CurrentValue
Dim original As Object = prop.OriginalValue
Dim prop As DbPropertyEntry(Of YourEntityType, PropertyType) = entry.Property(Function(x) x.PropertyName)
Dim current As PropertyType = prop.CurrentValue
Dim original As PropertyType = prop.OriginalValue
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Sorry friend , but in can't implement your suggestions to my expression. What can I change to my expression because I'm using reflection , and I know only this to get the current value :
.GetValue(obj, Nothing)
How to get the original value.
There's no .GetCurrentValue.
Please look my expression .
Thank you !
|
|
|
|