|
SqlFileStream sourceStream = new SqlFileStream(path, context, FileAccess.Read);
System.ComponentModel.Win32Exception occurred
HResult=-2147467259
Message=Access is denied
Source=System.Data
ErrorCode=-2147467259
NativeErrorCode=5
StackTrace:
at System.Data.SqlTypes.SqlFileStream.OpenSqlFileStream(String path, Byte[] transactionContext, FileAccess access, FileOptions options, Int64 allocationSize)
at System.Data.SqlTypes.SqlFileStream..ctor(String path, Byte[] transactionContext, FileAccess access, FileOptions options, Int64 allocationSize)
at System.Data.SqlTypes.SqlFileStream..ctor(String path, Byte[] transactionContext, FileAccess access)
at MusicStoreImageManager.ProductDB.ReadImage(Int32 imageID) in c:\Users\Gerry\Downloads\sq12_allfiles\SQL Server 2012\Projects\C#\Chapter 20b\MusicStoreImageManager\ProductDB.cs:line 132
InnerException:
|
|
|
|
|
Turn on first chance exceptions and the debugger will break at the correct spot whether you have try/catch blocks or not. Then examine the *original* exception to get the real error message and line number.
|
|
|
|
|
That showed me the issue:
SqlFileStream sourceStream = new SqlFileStream(path, context, FileAccess.Read);
System.ComponentModel.Win32Exception occurred
HResult=-2147467259
Message=Access is denied
Source=System.Data
ErrorCode=-2147467259
NativeErrorCode=5
StackTrace:
at System.Data.SqlTypes.SqlFileStream.OpenSqlFileStream(String path, Byte[] transactionContext, FileAccess access, FileOptions options, Int64 allocationSize)
at System.Data.SqlTypes.SqlFileStream..ctor(String path, Byte[] transactionContext, FileAccess access, FileOptions options, Int64 allocationSize)
at System.Data.SqlTypes.SqlFileStream..ctor(String path, Byte[] transactionContext, FileAccess access)
at MusicStoreImageManager.ProductDB.ReadImage(Int32 imageID) in c:\Users\Gerry\Downloads\sq12_allfiles\SQL Server 2012\Projects\C#\Chapter 20b\MusicStoreImageManager\ProductDB.cs:line 132
InnerException:
|
|
|
|
|
OK, according to the docs, SqlFileStream requires integrated security. SQL server authentication is not supported.
|
|
|
|
|
Thank You for the Help it is greatly appreciated..
Modified the connection string a new error is produced:
imagePictureBox.Image = System.Drawing.Image.FromStream(ms);
System.ArgumentException occurred
HResult=-2147024809
Message=Parameter is not valid.
Source=System.Drawing
StackTrace:
at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement, Boolean validateImageData)
at System.Drawing.Image.FromStream(Stream stream)
at MusicStoreImageManager.ImageManagerForm.imageIDComboBox_SelectedIndexChanged(Object sender, EventArgs e) in c:\Users\Gerry\Downloads\sq12_allfiles\SQL Server 2012\Projects\C#\Chapter 20b\MusicStoreImageManager\ImageManagerForm.cs:line 45
InnerException:
|
|
|
|
|
That's on the reading side, correct? Is the image correctly inserted into the database now?
|
|
|
|
|
No, it is located below the part i have in Bold and Italic is what produces the error. If i go to the debugger and select Continue it will continue to load the form and have an successful upload to the database.
private void imageIDComboBox_SelectedIndexChanged(
object sender, EventArgs e)
{
try
{
int imageID = Convert.ToInt32(imageIDComboBox.Text);
Byte[] imageByteArray = ProductDB.ReadImage(imageID);
MemoryStream ms = new MemoryStream(imageByteArray);
imagePictureBox.Image = System.Drawing.Image.FromStream(ms);
ms.Close();
}
catch (Exception ex)
{
MessageBox.Show(this, ex.Message, "Error");
}
}
System.ArgumentException occurred
HResult=-2147024809
Message=Parameter is not valid.
Source=System.Drawing
StackTrace:
at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement, Boolean validateImageData)
at System.Drawing.Image.FromStream(Stream stream)
at MusicStoreImageManager.ImageManagerForm.imageIDComboBox_SelectedIndexChanged(Object sender, EventArgs e) in c:\Users\Gerry\Downloads\sq12_allfiles\SQL Server 2012\Projects\C#\Chapter 20b\MusicStoreImageManager\ImageManagerForm.cs:line 45
InnerException:
|
|
|
|
|
So you just need to turn off first chance exceptions. Some areas of .Net work based on exceptions (i.e. serialization) and they are handled by the framework. Remember, the first chance exceptions let you catch exceptions before the try / catch does. You shouldn't normally run with them on.
|
|
|
|
|
Thank you for the help i turned off the first chance exceptions.
|
|
|
|
|
Time for one last post before going out for New Year (it's only five-and-half-hours away here).
I find it interesting that if you define a Dictionary:
private Dictionary<int, Action<int>> IntKeyValueCode = new Dictionary<int, Action<int>>();
private void Method1(int someInt, string someString, double someDouble)
{
MessageBox.Show(string.Format("Method1: int: {0} string: {1} double: {2}", someInt, someString, someDouble));
}
private string someString = "a string";
private double someDouble = 199.994;
private void TestCodeInDictinary()
{
IntKeyValueCode.Add(1, value => Method1(value, someString, someDouble));
IntKeyValueCode[1](100);
} What is of interest to me is that this appears to "defy" what I believe to be the requirement that a Type declaration of Action<int> would allow only the assignment to it of a pointer to a method body with one-and-only one parameter ... of Type 'int.
Thoughts ?
«A man will be imprisoned in a room with a door that's unlocked and opens inwards ... as long as it does not occur to him to pull rather than push» Wittgenstein
modified 2-Jan-15 8:49am.
|
|
|
|
|
I do not see what the problem with this...
value => Method1(value, someString, someDouble)
This line does not say that the function you run inside the delegate can not get any value you want (number and type), it talking about the delegate itself, so you can not write this:
(val1, val2) => Method(val1, val2)
You may see the compiled code to understand more...
private void TestCodeInDictinary()
{
this.IntKeyValueCode.Add(1, delegate(int value)
{
this.Method1(value, this.someString, this.someDouble);
});
}
Skipper: We'll fix it.
Alex: Fix it? How you gonna fix this?
Skipper: Grit, spit and a whole lotta duct tape.
|
|
|
|
|
I believe it is the Action itself that is getting the parameter passed to it, 'value => ', not the method that you're calling inside the Action. Hell, you don't even need to use the parameters passed in
To illustrate:
private Dictionary<int, Action<int, int>> IntKeyValueCode = new Dictionary<int, Action<int, int>>();
private void TestCodeInDictinary()
{
IntKeyValueCode.Add(1, (value1, value2) => Method1(thisCodeDoesnt, giveAShit, whatsPassedIn));
IntKeyValueCode[1](100, 200);
}
|
|
|
|
|
Exactly!
Action<t> declares a delegate, where the left side of the lambda (=>) must fit the parameter list of that delegate (the <T> part) and the right side is what executed when the delegate called...
Skipper: We'll fix it.
Alex: Fix it? How you gonna fix this?
Skipper: Grit, spit and a whole lotta duct tape.
modified 31-Dec-14 12:31pm.
|
|
|
|
|
Hi,
any sample code i can fulfill the following?
creating internet explorer toolbar that extract all the elements from the active tab
So far, i can only find toolbar that just redirect / navigate to another page.
Please help.
|
|
|
|
|
You might want to define precisely what you mean by "extract all the elements".
|
|
|
|
|
Did you look at in system.net?
Following code extracts favicon from websites.
string u="web site address";
Uri url = new Uri(u);
String iconurl = "http://" + url.Host + "/favicon.ico";
WebRequest request = WebRequest.Create(iconurl);
try
{
WebResponse response = request.GetResponse();
Stream s = response.GetResponseStream();
return Image.FromStream(s);
}
...
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
I have the Private key (from 'pem' file) as string.
But the method which im using accepts the parameter as 'Private key'
getSignaute(java.security.PrivateKey pk, string inputxml)
how to convert string to private key (in C#.net)
|
|
|
|
|
|
Hello,
i am getting stuck to apply a feature in my project with Drag&Drop developing in WPF/C#, i can post you an example of code of what i want to do as follow :
<Grid x:Name="LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid x:Name="box1" Grid.Row="0" >
<Grid Name="grid1" Background="Aqua" Margin="15"></Grid>
</Grid>
<Grid x:Name="box2" Grid.Row="1" >
<Grid Name="grid2" Background="blue" Margin="15"></Grid>
</Grid>
<Grid x:Name="box3" Grid.Row="2" >
<Grid Name="grid3" Background="green" Margin="15"></Grid>
</Grid>
</Grid>
each Grid(box) contains another Grid my simple purpose is to drag the "grid1" to the "box2" then automatically the "grid2" go to the "box1" and this rule is applied every time i want drag&drop ; the Grid "box" is always not movable .
From many days i check out many project and library online as GongSolutions.Wpf.DragDrop,Blacklight.ShowCase.WPF and else but don't cover my request because in each grid there are many controls binding data(in the real project should be 30 grid more all controls ) then an ItemControl don't cover my purpose.
I am easy to do a simple Drag&Drop but in this case is more complicated for me then i ask you kindly if you have any suggestion or idea to work out this case.
I give in anticipate my apologies if my question result weird as i have not much experience in WPF.
Thank you in anticipate
|
|
|
|
|
That looks more like XAML (WPF) than C#; please use the correct forum.
|
|
|
|
|
Dear Richard,
thank you so much i will move this post to the correct forum,i give you my apologies for this mistake.
|
|
|
|
|
Hi,
I've encountered a few scenarios similar to the one I'm posting about today and I'd like to know a good way to write code for this scenario rather than the hokey work arounds I've been doing.
The scenario is that I have x and y coordinates and a value.
I want to sort by the x coordinate, then the y coordinate and then plot the value. In powershell I could create an object and then its properties, can I do that easily in c#? Or is there a better way to handle that? The sorting I'm not sure how to do either? I also am receiving them out of order.
Thanks for reading.
|
|
|
|
|
Let's assume that you are storing the data in a class that stores the properties as X and Y values. It's easy enough to sort the data using LINQ, first by ORDERBY on the X and then the Y. Do this in a single query.
|
|
|
|
|
Why sort it at all? You can plot unsorted values. :shrug:
On the other hand, part of what I was playing with over the last few days involved X,Y,value objects and I keep them in a Dictionary<int,object> (like a sparse* matrix, and the int Key is essentially a hash of the X and Y -- (X<<16)|Y ). In my case, I then use nested for loops to access the content of the Dictionary in the order I want them.
for ( y = miny ; y <= maxy ; y++ )
for ( x = minx ; x <= maxx ; x++ )
if ( data.ContainsKey ( hash ( x , y ) ) ...
This requires that I update the min and max x and y as I add items to the dictionary, but that's no big deal.
* There may be only 10% or fewer active items over the two-dimensional address space.
modified 29-Dec-14 17:03pm.
|
|
|
|
|
I've written this type of Class so many times I think I could write it half-asleep
using System.Collections.Generic;
using System.Linq;
namespace YetAnother
{
public class PointyPoint
{
public int X { set; get; }
public int Y { set; get; }
public double Value { set; get; }
public PointyPoint() {}
public PointyPoint(int x, int y, double value)
{
X = x;
Y = y;
Value = value;
}
}
public enum PointySortType
{
PSortAscendingX,
PSortAscendingY,
PSortDescendingX,
PSortDescendingY,
PSortAscendingValue,
PSortDescendingValue
}
public class PointyListClass : List<PointyPoint>
{
public PointyListClass() {}
public List<PointyPoint> PointySortedBy(PointySortType pSType, PointyListClass pointyList)
{
if (pointyList == null || pointyList.Count == 1) return null;
switch (pSType)
{
case PointySortType.PSortAscendingX:
{
return pointyList.OrderBy(pointy => pointy.X).ToList();
}
case PointySortType.PSortAscendingY:
{
return pointyList.OrderBy(pointy => pointy.Y).ToList();
}
case PointySortType.PSortDescendingX:
{
return pointyList.OrderByDescending(pointy => pointy.X).ToList();
}
case PointySortType.PSortDescendingY:
{
return pointyList.OrderByDescending(pointy => pointy.Y).ToList();
}
case PointySortType.PSortAscendingValue:
{
return pointyList.OrderBy(pointy => pointy.Value).ToList();
}
case PointySortType.PSortDescendingValue:
{
return pointyList.OrderByDescending(pointy => pointy.Value).ToList();
}
}
return null;
}
}
}
private void SomeButton_Click(object sender, EventArgs e)
{
PointyListClass pointyList = new PointyListClass
{
{new PointyPoint(100,400,199.99)},
{new PointyPoint(200,300,12.43)},
{new PointyPoint(300,200,-12333)},
{new PointyPoint(400,100,345.93)},
};
var pointyXAscending = pointyList.PointySortedBy(PointySortType.PSortAscendingX, pointyList).ToList();
var pointyYAscending = pointyList.PointySortedBy(PointySortType.PSortAscendingY, pointyList).ToList();
var pointyXDescending = pointyList.PointySortedBy(PointySortType.PSortDescendingX, pointyList).ToList();
var pointyDescending = pointyList.PointySortedBy(PointySortType.PSortDescendingY, pointyList).ToList();
var pointyValueAscending = pointyList.PointySortedBy(PointySortType.PSortAscendingValue, pointyList).ToList();
var pointyValueDescending = pointyList.PointySortedBy(PointySortType.PSortDescendingValue, pointyList).ToList();
}
«A man will be imprisoned in a room with a door that's unlocked and opens inwards ... as long as it does not occur to him to pull rather than push» Wittgenstein
|
|
|
|
|