1
我收到以下錯誤「無效的授權規範,無效的連接字符串屬性」無效的授權規範和無效的連接字符串屬性
//namespaces
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;
using System.IO;
using System.Data.OleDb;
namespace Database1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public bool IsValidConnectionForPrinting()
{
//string declaration
string str = @" Provider = SQLOLEDB; Data Source = sekhar; Database = DMS; UserId = sa; Password = 123";
//Oledbconnection to database
OleDbConnection oleDbcon = new OleDbConnection(str);
try
{
oleDbcon.Open();
MessageBox.Show("hai");
oleDbcon.Close();
}
//Exception
catch (Exception ex)
{
if (ex.Message.StartsWith("Invalid object name"))
{
MessageBox.Show(ex.Message.Replace("Invalid object name", "Table or view not found"), "Connection Test");
}
//Connection
private void btnConnTest_Click(object sender, EventArgs e)
{
if (IsValidConnectionForPrinting())
{
MessageBox.Show("Connection succeeded", "Connection Test");
}
}
}
}
哪一行出現錯誤?也許你的連接字符串不好? – gideon 2012-04-10 04:49:06
oleDbcon.Open(); 當連接嘗試打開時出現錯誤 – user1312412 2012-04-10 04:54:55
也許而不是您需要的數據庫初始目錄 – V4Vendetta 2012-04-10 05:23:39