|
Converting a string to/from binary is NOT encryption.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Is it any wonder so many businesses get hacked?
|
|
|
|
|
Hi,
I am creating a simple Form in VS 2010 by using access database as backend source data.
I dragged the access fields in the VS form, everything is fine but the drop down fields are just came as Text Fields instead of combobox.
So I manually created a combobox by assigning that access table field source. But after that also in preview (F5) the combobox comes as empty dropdown. But access has the values for those combo box.
Please let me know what I am doing wrong? Or is there any workaround to arrive the dropdown list in VS form?
Awaiting for the reply,
---
VS
|
|
|
|
|
Have you fixed this? There might be a connections string issue if you haven't fixed it yet.
"I've seen more information on a frickin' sticky note!" - Dave Kreskowiak
|
|
|
|
|
I'm using entity Framework 6 DBContext , Database First.
I have created the Model using wizard form an existing SQL server database.
Now on the app.config file , this connection string :
<connectionStrings>
<add name="MyEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl| res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=My_PC;initial catalog=MyDatabase;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
This is working on a PC with SQL server installed.
But if I try on a pc with SQL server Express , this is not working ( of course I have changed in the connection string the PC name. The database name is the same ).
What should I change in the above connection string in order to make it work on a SQL server express ?
My goal is to make this programmatically , so when my application is start , to test if is a SQL server or SQL server express environment and to make the changes on the app.config file .
Thank you !
|
|
|
|
|
You didn't provide the error message you get, but few things to check:
- 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.
|
|
|
|
|
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
|
|
|
|