不敢相信我不得不问这个问题,但我不能为我的生活连接到Oracle 11g数据库.
以下在使用时起作用System.Data.OracleClient- 但显然这是折旧的.使用完全相同的代码但使用时Oracle.DataAccess.OracleClient我得到以下错误
{"ORA-12545: Connect failed because target host or object does not exist"}
Run Code Online (Sandbox Code Playgroud)
这是我的代码
using (OracleConnection con = new OracleConnection("Data Source=orac;User Id=SYSTEM; Password=Pass;"))
{
con.Open();
Console.WriteLine("Connection opened");
OracleCommand cmd2 = new OracleCommand("SELECT * FROM SYSTEM.TABLE", con);
OracleDataReader oracleDataReader = cmd2.ExecuteReader();
while (oracleDataReader.Read())
{
Console.WriteLine(oracleDataReader[0]);
}
}
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮我解决我做错的事吗?
我必须将程序更改为32位Oracle.DataAccess.dll才能加载.
这甚至是正确的库使用???
谢谢
编辑
tnsnames.ora文件如下:
# tnsnames.ora Network Configuration File:
C:\app\UserName\product\11.2.0\dbhome_3\network\admin\tnsnames.ora
# Generated by Oracle configuration tools.
ORAC =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = …Run Code Online (Sandbox Code Playgroud) 在我开始的项目中,我正在使用以下2个库:
MahApps.Metro - http://mahapps.com/MahApps.Metro/
DataGridExtensions - https://datagridextensions.codeplex.com/
DatagridExtensions有一些非常好的数据网格过滤工具.唯一的问题是使用它会从数据网格中删除Metro风格.有什么方法可以将Metro Styling保留在datagrid上并使用扩展.
我在DataGridExtensions库中找到的唯一.xaml文件是generic.xaml文件.我修改了这个以包含任何样式的BasedOn,因为这在过去有效:
例如
<Style TargetType="CheckBox" BasedOn="{StaticResource {x:Type CheckBox}}>
Run Code Online (Sandbox Code Playgroud) 使用PrintDocument边距时遇到问题。
无论我做什么,我打印的所有内容总是有一个边距,这意味着没有任何东西在需要的地方对齐。
这是我用来创建的代码 PrintDocument
public void Print()
{
PrintDocument printDocument = new PrintDocument();
printDocument.DefaultPageSettings.PaperSize = new PaperSize("A5",583,827);
printDocument.OriginAtMargins = true;
printDocument.DefaultPageSettings.Margins.Top = 0;
printDocument.DefaultPageSettings.Margins.Left = 0;
printDocument.DefaultPageSettings.Margins.Right = 0;
printDocument.DefaultPageSettings.Margins.Bottom = 0;
if (!string.IsNullOrWhiteSpace(PrinterName))
{
printDocument.PrinterSettings.PrinterName = PrinterName;
}
printDocument.PrintController = new StandardPrintController();
printDocument.PrintPage += On_PrintPage;
printDocument.Print();
}
Run Code Online (Sandbox Code Playgroud)
该On_PrintPage方法具有对e.Graphics.Draw...方法的各种调用。
我怎样才能让我在 0,0 打印的东西打印在页面的左上角。我知道如果打印机无法打印到页面边缘那么远,它将是空白的,但是它应该这样做而不是在页面左上角打印 0,0。
我真的迷路了
我刚刚开始使用MVVM,如果我做了一些非常愚蠢的事情,那么道歉.我试着写一个非常简单的测试来看看我是否能记住一切,而对于我的生活,我不明白为什么它不起作用.
在我看来,我有一个textBox,其text属性绑定到ViewModel中的值.然后当按下按钮时,应该更改值并更新textBox.
我可以看到值确实改变了(我在buttom press命令中添加了MessageBox.Show()行)但是textBox没有更新.
我认为这意味着我没有正确实施INotifyPropertyChanged事件,但我无法看到我的错误.
有人能指出我正确的方向吗?
这是代码:
视图
<Window x:Class="Mvvm.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<StackPanel Orientation="Horizontal" VerticalAlignment="Top">
<TextBox Height="40" Width="200" Text="{Binding helloWorld.Message, UpdateSourceTrigger=PropertyChanged}"/>
<Button Command="{Binding UpdateTimeCommand}">Update</Button>
</StackPanel>
</Window>
Run Code Online (Sandbox Code Playgroud)
在视图后面
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
DataContext = new ViewModel.MainWindowViewModel();
}
}
Run Code Online (Sandbox Code Playgroud)
视图模型
namespace Mvvm.ViewModel
{
internal class MainWindowViewModel
{
private HelloWorld _helloWorld;
/// <summary>
/// Creates a new instance of the ViewModel Class
/// </summary>
public MainWindowViewModel()
{
_helloWorld = new HelloWorld("The …Run Code Online (Sandbox Code Playgroud) 这是我第一次需要使用SqlDependency,所以我希望这是我犯的一个愚蠢的错误.
我遇到的问题是当sql表更改时,OnChanged事件不会触发.没有错误或任何事情只是它不会触发.
这是代码
public class SqlWatcher
{
private const string SqlConnectionString = "Data Source = CN-PC08\\DEV; Initial Catalog=DEP; User = sa; Password=******";
public SqlWatcher()
{
SqlClientPermission perm = new SqlClientPermission(System.Security.Permissions.PermissionState.Unrestricted);
perm.Demand();
SqlCommand cmd = new SqlCommand("SELECT [DataAvaliable], [RowNumber] FROM [dbo].[Trigger]", new SqlConnection(SqlConnectionString));
SqlDependency sqlDependency = new SqlDependency(cmd);
sqlDependency.OnChange += On_SqlBitChanged;
}
private void On_SqlBitChanged(object sender, SqlNotificationEventArgs sqlNotificationEventArgs)
{
SqlDependency dependency = (SqlDependency)sender;
dependency.OnChange -= On_SqlBitChanged;
// Fire the event
if (NewMessage != null)
{
NewMessage(this, new EventArgs());
}
}
public …Run Code Online (Sandbox Code Playgroud) 我在使用 caliburn 将 TextboxHelper.ButtonCommand(来自 mahapps.metro)绑定到我的视图模型时遇到问题。
目前我使用委托命令进行这项工作。
看法:
<TextBox Name="TextBoxContent"
mui:TextboxHelper.ButtonContent="s"
mui:TextboxHelper.ButtonCommand="{Binding DelCommand, Mode=OneWay}"
Style="{DynamicResource ButtonCommandMuiTextBox}" />
Run Code Online (Sandbox Code Playgroud)
视图模式:
ICommand DelCommand
{
get {return new Command();}
}
void Command() { //Handle press here }
Run Code Online (Sandbox Code Playgroud)
但是我真的很想使用 caliburn 而不是委托命令来实现这一点。我试过在文本框上使用事件触发器无济于事,就像这样......
<TextBox Name="TextBoxContent" mui:TextboxHelper.ButtonContent="s"
Style="{DynamicResource ButtonCommandMuiTextBox}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="mui:TextboxHelper.ButtonCommand">
<i:EventTrigger.Actions>
<cal:ActionMessage MethodName="Command"/>
</i:EventTrigger.Actions>
</i:EventTrigger>
</i:Interaction.Triggers>
</TextBox>
Run Code Online (Sandbox Code Playgroud)
有什么理由不能这样做吗?
谢谢
我已经开始在实体框架中使用CodeFirst方法.
运行我的代码时,我无法在DbContext - ProductsDb中对DbSets执行任何操作
我检查了连接字符串,我认为它是正确的但尝试执行操作会导致错误
参数源不能为null.
这是ProductsDb类
public class ProductsDb : DbContext
{
public ProductsDb(string connectionString) : base(connectionString)
{
}
public ProductsDb()
{
}
public DbSet<AProduct> AProducts;
public DbSet<BProduct> BProducts;
public DbSet<CProduct> CProducts;
public DbSet<DProduct> DProducts;
}
Run Code Online (Sandbox Code Playgroud)
连接字符串在app.config中定义如下:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="ProductsDb" providerName="System.Data.SqlClient"
connectionString="Data Source=MyPC\DEV;Initial Catalog=Test;User ID=sa;
Password=pass;" />
</connectionStrings>
</configuration>
Run Code Online (Sandbox Code Playgroud)
抛出错误的代码是:
GetAProduct(string id)
{
AProduct aProduct = null;
using (ProductsDb productsDb = new ProductsDb())
{
aProduct = (from a in productsDb.AProducts
where a.Id== id
select …Run Code Online (Sandbox Code Playgroud) 我有一个问题,当我将该对象设置为数据绑定时,我无法创建使用自定义对象属性的用户控件.
试着解释一下我的意思是代码.自定义对象:
public class MyObj
{
public string Text { get; set; }
public MyObj(string text)
{
Text = text;
}
}
Run Code Online (Sandbox Code Playgroud)
用户控制代码背后:
/// <summary>
/// Interaction logic for MyControl.xaml
/// </summary>
public partial class MyControl : UserControl
{
public static readonly DependencyProperty ObjectProperty =
DependencyProperty.Register("Object", typeof (MyObj), typeof (MyControl), new PropertyMetadata(default(MyObj)));
public MyObj Object
{
get { return (MyObj) GetValue(ObjectProperty); }
set { SetValue(ObjectProperty, value); }
}
public MyControl()
{
InitializeComponent();
}
}
Run Code Online (Sandbox Code Playgroud)
用户控制XAML:
<UserControl x:Class="Test.MyControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" …Run Code Online (Sandbox Code Playgroud) 请道歉,如果这是一个非常愚蠢的问题,但我刚刚开始使用caliburn.micro并且我正在努力获得eventAggregator,似乎没有任何订阅...
我不确定问题是视图模型还是引导程序.这是viewmodel:
class MainWindowViewModel : Screen
{
private readonly IEventAggregator _eventAggregator;
public MainWindowViewModel(IEventAggregator eventAggregator)
{
_eventAggregator = eventAggregator;
_eventAggregator.Subscribe(this);
}
public void SayHello()
{
_eventAggregator.Publish("Hello World!");
}
public void Handle(string message)
{
MessageBox.Show(message);
}
}
Run Code Online (Sandbox Code Playgroud)
引导程序:
class AppBootstrapper : Bootstrapper<MainWindowViewModel>
{
public static readonly Container ContainerInstance = new Container();
protected override void Configure()
{
ContainerInstance.Register<IWindowManager, WindowManager>();
ContainerInstance.RegisterSingle<IEventAggregator,EventAggregator>();
ContainerInstance.Register<MainWindowViewModel, MainWindowViewModel>();
ContainerInstance.Verify();
}
protected override IEnumerable<object> GetAllInstances(Type service)
{
return ContainerInstance.GetAllInstances(service);
}
protected override object GetInstance(System.Type service, string key)
{
return ContainerInstance.GetInstance(service); …Run Code Online (Sandbox Code Playgroud) 我目前正在开发一个应用程序,用户可以在画布上动态创建/移动TextBlocks.一旦他们将TextBlocks定位在他们想要的位置,他们就可以按下打印按钮,这将导致ZPL打印机打印当前显示在屏幕上的内容.
通过从每个TextBlock获取以下值来构建ZPL命令:
但是我找不到让打印输出类似于屏幕显示的方法.我想这是因为Canvas.Left和Canvas.Right的值与打印机DPI不匹配.
这是我目前正在使用的转换(因为我认为Canvas.Left = 1表示1/96英寸)(画布的左上角是0,0)
public double GetZplXPosition(UIElement uiElement)
{
int dpiOfPrinter = 300;
double zplXPosition = (Canvas.GetLeft(uiElement) / 96.0) * dpiOfPrinter;
return zplXPosition;
}
Run Code Online (Sandbox Code Playgroud)
我可以在"实际尺寸"中显示控件.使用的纸张将始终为A5(8.3英寸x 5.8英寸).
我想在Canvas周围使用一个视图框,其宽度和高度设置为830 x 580(A5的比例正确)但是这没有帮助.
有什么建议??
谢谢
Sonarqube 显示的项目和问题总数不正确。
项目总数说 4,但只有 2 个。声称有 78 个错误,但没有,结果部分中没有显示。(见下文)
我检查了数据库分组[projects]表,[project_uuid]只返回 2 行。
正在使用 Sonarqube v6.2,如果有任何不同,则使用 SQL Server 数据库。这可能是一个设置问题,我几天前才设置了这个实例,但我不确定除了项目表所在的数据库之外,我不知道在哪里检查。
为什么以下程序只运行有限数量的被阻止任务.限制数似乎是机器上的核心数.
最初,当我写这篇文章时,我希望看到以下内容:
然而输出是:
当在具有32个内核的服务器上运行时,程序确实按照我的预期运行.
class Program
{
private static object _lock = new object();
static void Main(string[] args)
{
int completeJobs = 1;
var limiter = new MyThreadLimiter();
for (int iii = 1; iii < 100000000; iii++)
{
var jobId = iii;
limiter.Schedule()
.ContinueWith(t =>
{
lock (_lock)
{
completeJobs++;
Console.WriteLine("Job: " + completeJobs + " scheduled");
}
});
}
Console.ReadLine();
}
}
class MyThreadLimiter
{
readonly SemaphoreSlim _semaphore …Run Code Online (Sandbox Code Playgroud) c# ×11
wpf ×5
mvvm ×3
printing ×2
sql ×2
c#-4.0 ×1
data-binding ×1
dpi ×1
gdi+ ×1
oracle ×1
sonarqube ×1
sql-server ×1
task ×1
wpfdatagrid ×1
zpl ×1