使用PowerShell调用存储过程

时间:2017-05-04 09:26:34

标签: sql-server powershell stored-procedures

我试图通过运行以下命令从PowerShell调用存储过程。存储过程的名称是sp_sample(驻留在ssms中)。但是我无法在powershell中看到代码的任何输出,也没有触发过程。有人可以纠正它。

$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = "Server=LABVM-
 40\RTC;Database=testDB;Integrated Security=True"
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand
$SqlCmd.CommandText ="sp_sample"
$SqlCmd.Connection = $SqlConnection
$sqlConnection.Open()
$Result = $SqlCmd.ExecuteNonQuery()
$sqlConnection.Close()

PS:我对powershell没有任何了解,我从互联网上选择了上述代码。

1 个答案:

答案 0 :(得分:4)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Parabola : MonoBehaviour {

public GameObject linePrefab, pointV;

public float offset, amp, speed;
public int freq;
public float directrixLength;
public int resolution;

private Vector3 mouse, prev;
private Vector3 directrix;
private Vector3 focusPoint, directrixPointMid, directrixPointL, directrixPointR;
private Vector3 focalLine;
private Vector3 p;
private List<List<Vector3>> pointsR = new List<List<Vector3>>();
private List<LineRenderer> lines = new List<LineRenderer>();
public Renderer render;

void Start () 
{
    render.material.SetInt("_Length", resolution);
    render.material.SetVectorArray("_Points", new Vector4[resolution]); 

    prev = mouse;
    int i = 0;
    while(i <= freq)
    {
        GameObject g = Instantiate(linePrefab);
        g.transform.SetParent(transform);
        g.transform.localPosition = Vector3.zero;
        LineRenderer line = g.GetComponent<LineRenderer>();
        line.positionCount = resolution;
        lines.Add(line);
        List<Vector3> lR = new List<Vector3>();
        pointsR.Add(lR);
        i++;
    }
}

void FixedUpdate () 
{
    if(Input.GetMouseButton(0))
    {
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;
        if(Physics.Raycast(ray, out hit, Mathf.Infinity, 1<<LayerMask.NameToLayer("Plane")))
        {
            mouse = new Vector3(hit.point.x,0,hit.point.z);
            StopCoroutine(CalculateParabola(mouse));
            StartCoroutine(CalculateParabola(mouse));
            transform.position = mouse;
            transform.forward = -focalLine;
        }
    }
}
IEnumerator CalculateParabola(Vector3 v)
{
    while(prev != v)
    {
        focalLine = prev - v;
        //calculate a parabola for each n in frequency, make it go wider the higher n is
        for(int n=0; h<=freq; n++)
        {
            pointsR[n] = new List<Vector3>();
            float s = Vector3.Distance(prev.normalized,v.normalized)*speed;
            for(float i = -directrixLength/2; i<=(directrixLength+1)/2; i+=directrixLength/resolution)
            {
                p.x = pointV.transform.localPosition.x+(i*(freq-n+Time.fixedDeltaTime*s));
                p.z = ((amp*(freq-n))*(Time.fixedDeltaTime*s))*-Mathf.Pow(p.x,2)+(1+offset*n);
                pointsR[n].Add(p);
            }
            lines[h].SetPositions(pointsR[n].ToArray());
            //attempt to translate the points to a shader, only for the first parabola for now
            Vector4[] renderPoints = new Vector4[resolution];
            for(int i=0; i<resolution; i++)
            {
                renderPoints[i] = transform.TransformPoint(pointsR[0][i]) - render.transform.position;
            }
            render.material.SetVectorArray("_Points", renderPoints); 
        }
        yield return new WaitForSeconds(0.1f);
        prev = v;
    }
}
}