我收到以下错误“无效的授权规范,无效的连接字符串属性”
//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");
}
}
}
}