小编Ton*_*Nam的帖子

使用代码或脚本启用tcp\ip远程连接到sql server express已安装的数据库(查询)

我正在使用我的应用程序部署sql express.我希望该数据库引擎接受远程连接.我知道如何通过启动sql server配置管理器,启用tcp/ip连接,指定端口等来配置该手册.我想知道是否可以从命令行执行相同的操作.

或许我必须在visual studio中创建一个"SQL Server 2008 Server Project".

编辑1

我在这里发布了相同的问题,但我想在已经安装的sql express实例上做同样的事情.看看这里的问题

编辑2

我发现这些链接声称做了类似的事情,但我仍然无法使其发挥作用.

1)http://support.microsoft.com/kb/839980

2)http://social.msdn.microsoft.com/Forums/en-US/sqlexpress/thread/c7d3c3af-2b1e-4273-afe9-0669dcb7bd02/

3)http://www.sql-questions.com/microsoft/SQL-Server/34211977/can-not-connect-to-sql-2008-express-on-same-lan.aspx

4)http://datazulu.com/blog/post/Enable_sql_server_tcp_via_script.aspx


编辑3

正如Krzysztof在他的回答中所说,我需要(以及我所知道的其他需要的东西)

1 - 启用TCP/IP

在此输入图像描述

我已经设法在安装传递参数的SQLExpress的新实例时执行此操作 /TCPENABLED=1.当我在这个例子中安装sql express时.sql express的实例将启用TCP/IP

2 - 在防火墙中打开正确的端口

(我已经完成了这个manualy,但我相信我将能够弄清楚如何用c#来做到这一点)到目前为止,我必须使用这个控制台命令来解决问题:

netsh firewall set portopening protocol = TCP port = 1433 name = SQLPort mode = ENABLE scope = SUBNET profile = CURRENT
Run Code Online (Sandbox Code Playgroud)

3 - 修改TCP/IP属性启用IP地址

在此输入图像描述

我一直无法弄清楚如何启用IP,更改端口等.我认为这将是更复杂的解决步骤

4 - 在sql server中启用混合模式身份验证

在此输入图像描述

我已经设法在安装SQL Express时执行此操作,传递参数/SECURITYMODE=SQL参考步骤1的链接.

SQL Server Express要求此身份验证类型接受远程连接.

5 - 更改用户(sa)默认passowrd …

configuration cmd database-connection remote-connection sql-server-express

39
推荐指数
1
解决办法
11万
查看次数

将DateTime转换为long,反之亦然

我想将日期作为数字存储在表格中.我知道怎么做,但我不知道怎么回去.如何将长变量强制转换为ToDateTime.

DateTime now = DateTime.Now;
long t = now.ToFileTime();
DateTime today = t.ToDateTime;  // I am looking for something like this line. This Method does not exist
Run Code Online (Sandbox Code Playgroud)

我知道有很多方法可以将DateTime转换为long.我不介意使用哪种技术.我只想有一种方法可以来回转换.

.net c# datetime

38
推荐指数
4
解决办法
9万
查看次数

设置私有字段的值

为什么以下代码不起作用:

class Program
{
    static void Main ( string[ ] args )
    {
        SomeClass s = new SomeClass( );

        s.GetType( ).GetField( "id" , System.Reflection.BindingFlags.NonPublic ) // sorry reasently updated to GetField from GetProperty...
            .SetValue( s , "new value" );
    }
}


class SomeClass
{
    object id;

    public object Id 
    {
        get
        {
            return id;
        }
    }   
}
Run Code Online (Sandbox Code Playgroud)

我试图设置私有字段的值.


这是我得到的例外:

System.NullReferenceException未处理Message = Object引用未设置为对象的实例.来源= ConsoleApplication7
StackTrace:位于C:\ Users\Antonio\Desktop\ConsoleApplication7\ConsoleApplication7\Program.cs中的Program.Main(String [] args):位于System的System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly,String [] args)的第18行. System.Threading.ExecutionContext.Run上的System.Threading.ThreadHelper.ThreadStart_Context(Object state)中的Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()中的AppDomain.ExecuteAssembly(String assemblyFile,Evidence assemblySecurity,String [] args)(ExecutionContext executionContext System.Threading.ThreadHelper.ThreadStart()中的System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback回调,对象状态),ContextExallback回调,对象状态,布尔值ignoreSyncCtx:InnerException:

c# reflection

30
推荐指数
1
解决办法
3万
查看次数

从wpf中的文件路径列表填充树视图

有几个示例说明如何从文件路径集合(例如其他示例)填充树视图.我似乎无法为WPF找到这样的例子.我知道我可以集成Windows窗体并使用不同的控件以使其工作但如果我可以使用wpf treeview控件执行相同的操作将会很好.我想要构建的树视图包含大约50,000个文件,因此我认为如果将它绑定到某个东西会更好.但首先在绑定它之前,我认为基于字符串列表构造一个(字符串包含文件的路径)将是有帮助的.

c# wpf treeview code-behind

28
推荐指数
2
解决办法
3万
查看次数

看看img的src是否存在

当我放置一个img标签时,我动态创建了src属性.有没有办法测试src(图像所在的路径)是否实际存在于javascript中以避免获取:

在此输入图像描述

html javascript image src

27
推荐指数
3
解决办法
4万
查看次数

通过user32.dll中的SendInput发送密钥

我使用这块板作为键盘用于演示目的.

无论如何,长话短说一切都很好,除了很少的情况.我使用user32.dll中的SendInput函数发送击键.

所以我的程序看起来像:

static void Main(string[] args)
{
    Console.Write("Press enter an on the next secont the key combination shift+end will be send");
    Console.Read();

    Thread.Sleep(1000);

    SendKeyDown(KeyCode.SHIFT);
    SendKeyPress(KeyCode.END);
    SendKeyUp(KeyCode.SHIFT);

    Console.Read(); 
    Console.Read();
}

[DllImport("user32.dll", SetLastError = true)]
private static extern uint SendInput(uint numberOfInputs, INPUT[] inputs, int sizeOfInputStructure);

/// <summary>
/// simulate key press
/// </summary>
/// <param name="keyCode"></param>
public static void SendKeyPress(KeyCode keyCode)
{
    INPUT input = new INPUT {
        Type = 1
    };
    input.Data.Keyboard = new KEYBDINPUT() { …
Run Code Online (Sandbox Code Playgroud)

c# user32 sendkeys sendinput

26
推荐指数
1
解决办法
6万
查看次数

从流中读取数据的最有效方法

我有一个使用对称加密来加密和解密数据的算法.无论如何,当我要解密时,我有:

CryptoStream cs = new CryptoStream(ms, cryptoTransform, CryptoStreamMode.Read);
Run Code Online (Sandbox Code Playgroud)

我必须从cs CryptoStream中读取数据并将该数据放入一个字节数组中.所以一种方法可能是:

  System.Collections.Generic.List<byte> myListOfBytes = new System.Collections.Generic.List<byte>();

   while (true)
   {
                int nextByte = cs.ReadByte();
                if (nextByte == -1) break;
                myListOfBytes.Add((Byte)nextByte);
   }
   return myListOfBytes.ToArray();
Run Code Online (Sandbox Code Playgroud)

另一种技术可能是:

ArrayList chuncks = new ArrayList();

byte[] tempContainer = new byte[1048576];

int tempBytes = 0;
while (tempBytes < 1048576)
{
    tempBytes = cs.Read(tempContainer, 0, tempContainer.Length);
    //tempBytes is the number of bytes read from cs stream. those bytes are placed
    // on the tempContainer array

    chuncks.Add(tempContainer);

}

// later do …
Run Code Online (Sandbox Code Playgroud)

c# performance stream

25
推荐指数
2
解决办法
6万
查看次数

更改UIImageView模式iPhone/iPad

如果我有一个模式设置为居中的UIImageView,例如如何将其更改为其他内容,例如方面适合代码?

在此输入图像描述

iphone objective-c uiimageview ipad

23
推荐指数
2
解决办法
2万
查看次数

为什么LZMA SDK(7-zip)这么慢

我发现7-zip很棒,我想在.net应用程序上使用它.我有一个10MB的文件(a.001),它需要:

在此输入图像描述

2秒编码.

如果我能在c#上做同样的事情,那将会很好.我已经下载了http://www.7-zip.org/sdk.html LZMA SDK c#源代码.我基本上将CS目录复制到visual studio中的控制台应用程序中: 在此输入图像描述

然后我编译和eveything编译顺利.所以在输出目录中我放置了a.00110MB大小的文件.关于我放置的源代码的主要方法:

[STAThread]
    static int Main(string[] args)
    {
        // e stands for encode
        args = "e a.001 output.7z".Split(' '); // added this line for debug

        try
        {
            return Main2(args);
        }
        catch (Exception e)
        {
            Console.WriteLine("{0} Caught exception #1.", e);
            // throw e;
            return 1;
        }
    }
Run Code Online (Sandbox Code Playgroud)

当我执行控制台应用程序时,应用程序运行良好,我得到a.7z工作目录上的输出.问题是需要很长时间.执行大约需要15秒!我也试过/sf/answers/614314921/方法,这也需要很长时间.为什么它比实际程序慢10倍?

即使我设置只使用一个线程: 在此输入图像描述

它仍然需要更少的时间(3秒对15):


(编辑)另一种可能性

可能是因为C#比汇编还是C慢?我注意到该算法执行了大量繁重的操作.例如,比较这两个代码块.他们都做同样的事情:

C

#include <time.h>
#include<stdio.h>

void main()
{
    time_t now; 

    int i,j,k,x;
    long …
Run Code Online (Sandbox Code Playgroud)

c# compression performance 7zip lzma

22
推荐指数
2
解决办法
1万
查看次数

RijndaelManaged vs AesCryptoServiceProvider(AES加密)

我需要使用AES加密数据.在研究时我发现了AesCryptoServiceProvider类.

我对加密知之甚少,我不知道初始化向量(IV)是什么,所以我尝试在堆栈溢出中搜索AES示例,这引出了我的这个问题.

为什么堆栈溢出链接使用RijndaelManaged类?是RijndaelManaged的AesCryptoServiceProvider类做同样的事情?

.net c# encryption aes

22
推荐指数
1
解决办法
2万
查看次数