繁体   English   中英

Windows Server 2008 R2上未运行的本地Pragramm运行

[英]Local Pragramm running not running on windows Server 2008 R2

大家好,我已经用C#编写了一个程序。 该代码在我的本地机器上使用mssql express。 该程序没有任何错误,它正在运行。 但是,当我在Windows Server 2008 R2上上载该版本时,该程序将无法运行。 因此,该程序非常大且复杂,并且具有许多类,因此我决定编写一个Simpel程序进行测试。 和我有同样的问题

这是用于Simpel的测试的Test Exampel代码,仅连接到数据库并在其中写入Hallo。

Ausol程序是signet。 在服务器上安装了net 4.5。 所以我不知道为什么这不起作用

代码#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Data.Sql;
using System.Data.SqlTypes;
using System.Data.SqlClient;
using System.Windows;
using System.Windows.Shapes;

namespace WpfApplication2
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
public partial class MainWindow : Window
{
    SqlConnection DBConnection = null;
    public MainWindow()
    {
        InitializeComponent();
        DBConnection = new SqlConnection(GetConnectionString());
    }

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        MessageBox.Show("Hei ho");
        string Wort = "Hallo";
        string Name = Insersql(Wort);
        MessageBox.Show(Name);

    }

    //SQL open&insert
    private string Insersql(string Ausruf)
    {    
        try
        {
            DBConnection.Open();
            string Query = "insert into It_Infrastruktur (ITname) values('" + Ausruf + "')"; // speichern des ITelementnamen
            SqlCommand createCommand = new SqlCommand(Query, DBConnection);
            createCommand.ExecuteNonQuery();
            DBConnection.Close();  
        }
        catch (Exception ex)
        {
            throw ex;
        }
        return Ausruf;
    } 

    // SQL connection
    public void OpenSqlConnection()
    {
        string connectionString = GetConnectionString();

        using (SqlConnection connection = new SqlConnection(GetConnectionString()))
        {
            connection.ConnectionString = connectionString;
            connection.Open();
            Console.WriteLine("State: {0}", connection.State);
            Console.WriteLine("ConnectionString: {0}",
                connection.ConnectionString);
        }
    }

    private static string GetConnectionString()
    {


        return @"Data Source=(local);Initial Catalog=It_Infrastruktur;"
            + "Integrated Security=SSPI;";
        //return @"Data Source=(local)\SQLEXPRESS;Initial Catalog=It_Infrastruktur;"
        //    + "Integrated Security=SSPI;";
    }


 }
}

XAML代码

<Window x:Class="WpfApplication2.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">
    <Grid>
        <Button Content="Button" HorizontalAlignment="Left" Margin="178,120,0,0"     VerticalAlignment="Top" Width="75" Click="Button_Click"/>

    </Grid>
</Window>

sql脚本

create table It_Infrastruktur (
   ElementID                 bigint                        identity,
   ITname                    varchar(255)                  null,


   constraint PK_It_Infrastruktur primary key  (ElementID)
)
go

create table Netzwerkelement (
   Bezeichnung               varchar(255)                  null,
   IPadresse                 varchar(255)                  null,
   ITtype                    varchar(255)                  null,
   ITart                     varchar(255)                  null,
   Aartesys_artikelNr        varchar(255)                  null,
   Erwerbsdatum              varchar(255)                  null,
   Hersteller                varchar(255)                  null,
   Administrator             varchar(255)                  null,
   PW                        varchar(255)                  null,
   Port_anzahl               varchar(255)                  null,
   Hostip                    varchar(255)                  null,
   Beschreibung              varchar(MAX)                  null,
   Mac_Adresse               varchar(255)                  null,
   ElementID                 bigint                            null,

)
go

create table Logger (
   Mitarbeiter   varchar(225) null, 
   LogInfo      varchar(MAX)   null,
   LogDatum     DATETIME   null,

)
go  

谢谢你的帮助

所以我写了一个sibel conol输出

它看起来像是一个正确的问题,但我不知道为什么,因为我对此数据库具有管理员权限,因此我可以选择前1000行来完成所有工作

      Hello world
xxx\Desktop>"Hello world.exe"
Hello worldSystem.Data.SqlClient.SqlException (0x80131904): Cannot open database
 "It_Infrastruktur" requested by the login. The login failed.
Login failed for user 'xxx'.
   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception
, Boolean breakConnection, Action`1 wrapCloseInAction)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObj
ect stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand
 cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler,
TdsParserStateObject stateObj, Boolean& dataReady)
   at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cm
dHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, Tds
ParserStateObject stateObj)
   at System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlis
tOK)
   at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo
serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSn
iOpenTimeout, TimeoutTimer timeout, Boolean withFailover)
   at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo
serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirect
edUserInstance, SqlConnectionString connectionOptions, SqlCredential credential,
 TimeoutTimer timeout)
   at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTime
r timeout, SqlConnectionString connectionOptions, SqlCredential credential, Stri
ng newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance)
   at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdent
ity identity, SqlConnectionString connectionOptions, SqlCredential credential, O
bject providerInfo, String newPassword, SecureString newSecurePassword, Boolean
redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData r
econnectSessionData)
   at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOp
tions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConn
ectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)

   at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConn
ectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConne
ctionPoolKey poolKey, DbConnectionOptions userOptions)
   at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owning
Object, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
   at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection o
wningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection
)
   at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection ow
ningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean o
nlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& co
nnection)
   at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection ow
ningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbCon
nectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection
 owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions
, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(Db
Connection outerConnection, DbConnectionFactory connectionFactory, TaskCompletio
nSource`1 retry, DbConnectionOptions userOptions)
   at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection
 outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1
retry, DbConnectionOptions userOptions)
   at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 re
try)
   at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   at System.Data.SqlClient.SqlConnection.Open()
   at Hello_world.Program.Main(String[] args)
ClientConnectionId:402532f5-2b15-4075-87a9-b61ac0b0fd7b
Unhandled Exception: System.Data.SqlClient.SqlException: Cannot open database "I
t_Infrastruktur" requested by the login. The login failed.
Login failed for user 'xxx'.
   at Hello_world.Program.Main(String[] args)

确保SQL数据库接受Windows集成身份验证,并且已定义本地计算机用户并具有权限。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM