コード例 #1
0
ファイル: DbHelper.cs プロジェクト: tonyma/SCD-Merge-Wizard
        public static string GetBuiltConnectionString(string inputConnectionString)
        {
            MSDASC.DataLinks oDL = null;
            string           res = string.Empty;

            try
            {
                oDL = new MSDASC.DataLinksClass();
                ADODB.Connection conn = new ADODB.ConnectionClass();

                conn.ConnectionString = inputConnectionString;
                object oConn = (object)conn;
                if (oDL.PromptEdit(ref oConn))
                {
                    res = conn.ConnectionString;
                }
            }
            catch
            {
                try
                {
                    ADODB._Connection oConn = (ADODB._Connection)oDL.PromptNew();
                    if (oConn != null)
                    {
                        res = oConn.ConnectionString.ToString();
                    }
                }
                catch (Exception ex)
                {
                    MyExceptionHandler.NewEx(ex);
                }
            }

            return(string.IsNullOrEmpty(res) ? null : res);
        }
コード例 #2
0
        /// <summary>
        /// Get ConnectionString
        /// </summary>
        public string GetConnectionString(string connectionString)
        {
            if (string.IsNullOrEmpty(connectionString))
                return GetConnectionString();

            /*
              Reference DataLinks
               NOTE: Reference
                    C:\Program Files\Common Files\System\Ole DB\OLEDB32.DLL
                    (Was MSDASC.dll)
               SEE:
                    http://support.microsoft.com:80/support/kb/articles/Q225/1/32.asp
             */
            MSDASC.DataLinks dataLinks = new MSDASC.DataLinksClass();
            //note that a reference to:
            //  c:\Program Files\Microsoft.NET\Primary Interop Assemblies\adodb.dll
            //is also required to read the ADODB._Connection result
            ADODB._Connection connection;
            //are we editing an existing connect string or getting a new one?
            // edit connection string
            connection = new ADODB.ConnectionClass();
            connection.ConnectionString = connectionString;
            //set local COM compatible data type
            object oConnection = connection;
            //prompt user to edit the given connect string
            if ((bool)dataLinks.PromptEdit(ref oConnection))
            {
                return connection.ConnectionString;
            }
            return string.Empty;
        }
コード例 #3
0
ファイル: NumberService.cs プロジェクト: bejo4ever/antrian
        public static string GetConnectionString(string oldString)
        {
            String connectionString = String.Empty;
            var nuansaKey = Registry.CurrentUser.OpenSubKey("Software").OpenSubKey("Nuansa");
            if (nuansaKey == null)
            {
                if (!string.IsNullOrEmpty(oldString))
                    return oldString;
                MSDASC.DataLinks dataLinks = new MSDASC.DataLinksClass();
                object connection = new Connection();
                ((Connection)connection).ConnectionString = Settings.Default.ConnectionString;

                if (dataLinks.PromptEdit(ref connection))
                {
                    connectionString = ((Connection)connection).ConnectionString;
                    Settings.Default.ConnectionString = connectionString;
                }
                return connectionString;
            }

            RegistryKey key = nuansaKey.OpenSubKey("NCI Medismart").OpenSubKey("3.00").OpenSubKey("Database");
            if (key == null)
                throw new Exception("Tidak bisa buka registry NCI Medismart");

            for (int i = 0; i < 11; i++)
            {
                var value = (string)key.GetValue("key" + i);
                if (!(value.Contains("User ID") || value.Contains("Password")))
                    connectionString = connectionString + value;
            }
            connectionString += string.Format(";Password={0};User ID={1}", Settings.Default.DatabasePassword,
                                              Settings.Default.DatabaseUsername);
            return connectionString;
        }
コード例 #4
0
        private void btnSetConnect_Click(object sender, EventArgs e)
        {
            MSDASC.DataLinks  datalinks = new MSDASC.DataLinksClass();
            ADODB._Connection tmpconc   = new ADODB.ConnectionClass();

            if (TxtDbstr.Text == String.Empty)
            {
                tmpconc = (ADODB._Connection)datalinks.PromptNew();
                if (tmpconc != null)
                {
                    TxtDbstr.Text = tmpconc.ConnectionString;
                }
            }
            else
            {
                Object oconc = tmpconc;
                tmpconc.ConnectionString = TxtDbstr.Text;
                try
                {
                    if (datalinks.PromptEdit(ref oconc))
                    {
                        TxtDbstr.Text = tmpconc.ConnectionString;
                    }
                }
                catch
                {
                    tmpconc = (ADODB._Connection)datalinks.PromptNew();
                    if (tmpconc != null)
                    {
                        TxtDbstr.Text = tmpconc.ConnectionString;
                    }
                }
            }
        }
コード例 #5
0
        private static string PromptConnectionString(string initial, IntPtr handle)
        {
            bool ok = false;

            ADODB.Connection      conn   = null;
            MSDASC.DataLinksClass dlinks = null;
            try
            {
                // create objects we'll need
                dlinks = new MSDASC.DataLinksClass();
                conn   = new ADODB.ConnectionClass();

                // initialize object
                if (initial != null && initial.Length > 0)
                {
                    conn.ConnectionString = initial;
                }

                // show connection picker dialog
                object obj = conn;
                dlinks.hWnd = (int)handle;                 // << make it modal
                ok          = dlinks.PromptEdit(ref obj);
            }
            catch (Exception x)
            {
                FlexReportDesignerApp.MessageForm.Error(string.Format(FlexReportDesignerApp.Strings.SqlBuilderDialog.ErrCannotBuildConnFmt, x.Message));
            }

            // return what we got
            return(ok ? conn.ConnectionString : initial);
        }
コード例 #6
0
        protected string BrowseOleDbConnectionString(string connstr)
        {
            var dl = new MSDASC.DataLinksClass {
                hWnd = Handle.ToInt32()
            };

            var conn = new ADODB.Connection {
                ConnectionString = connstr
            };
            object objCn = conn;

            return(dl.PromptEdit(ref objCn) ? conn.ConnectionString : null);
        }
コード例 #7
0
        /// <summary>
        /// Displays a Connection String Builder (DataLinks) dialog.
        ///
        /// Credits:
        /// http://www.codeproject.com/cs/database/DataLinks.asp
        /// http://www.codeproject.com/cs/database/DataLinks.asp?df=100&forumid=33457&select=1560237#xx1560237xx
        ///
        /// Required COM references:
        /// %PROGRAMFILES%\Microsoft.NET\Primary Interop Assemblies\adodb.dll
        /// %PROGRAMFILES%\Common Files\System\Ole DB\OLEDB32.DLL
        /// </summary>
        /// <param name="currentConnectionString">Previous database connection string</param>
        /// <returns>Selected connection string</returns>
        private string PromptForConnectionString(string currentConnectionString)
        {
            MSDASC.DataLinks dataLinks = new MSDASC.DataLinksClass();
            ADODB.Connection dialogConnection;
            string           generatedConnectionString = string.Empty;

            if (currentConnectionString == String.Empty)
            {
                dialogConnection          = (ADODB.Connection)dataLinks.PromptNew();
                generatedConnectionString = dialogConnection.ConnectionString.ToString();
            }
            else
            {
                dialogConnection          = new ADODB.Connection();
                dialogConnection.Provider = "SQLOLEDB.1";
                ADODB.Property persistProperty = dialogConnection.Properties["Persist Security Info"];
                persistProperty.Value = true;

                dialogConnection.ConnectionString = currentConnectionString;
                dataLinks = new MSDASC.DataLinks();

                object objConn = dialogConnection;

                if (dataLinks.PromptEdit(ref objConn))
                {
                    generatedConnectionString = dialogConnection.ConnectionString.ToString();
                }
            }

            generatedConnectionString = generatedConnectionString.Replace("Provider=SQLOLEDB.1;", string.Empty);

            if
            (
                !generatedConnectionString.Contains("Integrated Security=SSPI") &&
                !generatedConnectionString.Contains("Trusted_Connection=True") &&
                !generatedConnectionString.Contains("Password="******"Pwd=")
            )
            {
                // BSG: Updated for null check on Value not only Password Property.
                if (dialogConnection.Properties["Password"].Value != null)
                {
                    generatedConnectionString += ";Password="******"Password"].Value.ToString();
                }
            }

            return(generatedConnectionString);
        }
コード例 #8
0
        private string PromptForConnectionString(string connectionString) 
        {

            string newConnectionString = string.Empty;

            try 
            {
                ADODB.Connection connection = null;
                MSDASC.DataLinks links = new MSDASC.DataLinksClass();

                if ((connectionString == null) || (connectionString.Length == 0)) 
                {
                    connectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Data Source=localhost";
                }
                else
                {
                    if (connectionString.IndexOf("Provider=SQLOLEDB.1") < 0)
                    {
                        connectionString = string.Concat("Provider=SQLOLEDB.1;", connectionString);
                    }
                }
                connection = new ADODB.ConnectionClass();
                connection.ConnectionString = connectionString;
                
                System.Object connectionObject = connection;
                bool success = links.PromptEdit(ref connectionObject); 
                if (success) 
                {           
                    connection = (ADODB.Connection)connectionObject;
                    newConnectionString = connection.ConnectionString;
                    // need to rip off the provider
                    string provider = string.Concat("Provider=", ((ADODB.Connection)connectionObject).Provider);
                    int index = newConnectionString.IndexOf(provider);
                    newConnectionString = newConnectionString.Remove(index, provider.Length + 1);
                }          
                else
                {
                    newConnectionString = connectionString;
                }
            }
            catch 
            {
                newConnectionString = string.Empty;
            }
            return newConnectionString;
        }
コード例 #9
0
ファイル: clsShared.cs プロジェクト: HarryiCalc/Test-Phakisa
        //===============================================================================
        public Boolean CreateUDLFile(string FileName, OleDbConnectionStringBuilder builder)
        {
            try
            {

                string conn = Convert.ToString(builder);
                MSDASC.DataLinksClass aaa = new MSDASC.DataLinksClass();
                aaa.WriteStringToStorage(FileName, conn, 1);
                return true;

            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("UDL error message: " + ex.Message);
                return false;
            }
        }
コード例 #10
0
ファイル: OleDbConnString.cs プロジェクト: trigrass2/myreport
        /// <summary>
        /// Prompts the user and edits a connection string.
        /// </summary>
        public static string EditConnectionString(IWin32Window owner, string connString)
        {
            try
            {
                // create objects we'll need
                var dlinks = new MSDASC.DataLinksClass();
                var conn   = new ADODB.ConnectionClass();

                // sanity
                if (dlinks == null || conn == null)
                {
                    Warning(owner, @"Failed to create DataLinks.

Please check that oledb32.dll is properly installed and registered.

(the usual location is c:\Program Files\Common Files\System\Ole DB\oledb32.dll).");
                    return(connString);
                }

                // initialize object
                if (!string.IsNullOrEmpty(connString))
                {
                    conn.ConnectionString = connString;
                }

                // show connection picker dialog
                object obj = conn;
                if (owner != null)
                {
                    dlinks.hWnd = (int)owner.Handle;
                }
                if (dlinks.PromptEdit(ref obj))
                {
                    connString = conn.ConnectionString;
                }
            }
            catch (Exception x)
            {
                Warning(owner, @"Failed to build connection string:
{0}", x.Message);
            }

            // done
            return(connString);
        }
コード例 #11
0
        private string PromptForConnectionString(string connectionString)
        {
            string newConnectionString = string.Empty;

            try
            {
                ADODB.Connection connection = null;
                MSDASC.DataLinks links      = new MSDASC.DataLinksClass();

                if ((connectionString == null) || (connectionString.Length == 0))
                {
                    connectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Data Source=localhost";
                }
                else
                {
                    if (connectionString.IndexOf("Provider=SQLOLEDB.1") < 0)
                    {
                        connectionString = string.Concat("Provider=SQLOLEDB.1;", connectionString);
                    }
                }
                connection = new ADODB.ConnectionClass();
                connection.ConnectionString = connectionString;

                System.Object connectionObject = connection;
                bool          success          = links.PromptEdit(ref connectionObject);
                if (success)
                {
                    connection          = (ADODB.Connection)connectionObject;
                    newConnectionString = connection.ConnectionString;
                    // need to rip off the provider
                    string provider = string.Concat("Provider=", ((ADODB.Connection)connectionObject).Provider);
                    int    index    = newConnectionString.IndexOf(provider);
                    newConnectionString = newConnectionString.Remove(index, provider.Length + 1);
                }
                else
                {
                    newConnectionString = connectionString;
                }
            }
            catch
            {
                newConnectionString = string.Empty;
            }
            return(newConnectionString);
        }
コード例 #12
0
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            Cursor.Current = Cursors.WaitCursor;
            string tmpReturn = string.Empty;

            MSDASC.DataLinks  dataLinks  = new MSDASC.DataLinksClass();
            ADODB._Connection connection = null;

            if (value.ToString() == String.Empty)
            {
                try
                {
                    connection = (ADODB._Connection)dataLinks.PromptNew();
                    if (connection != null)                    //if cancel is pressed connection is null
                    {
                        tmpReturn = connection.ConnectionString;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
            else
            {
                connection = new ADODB.ConnectionClass();
                connection.ConnectionString = value.ToString();

                object oConnection = connection;
                try
                {
                    if ((bool)dataLinks.PromptEdit(ref oConnection))
                    {
                        tmpReturn = connection.ConnectionString;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
            Cursor.Current = Cursors.Default;
            return(tmpReturn);
        }
コード例 #13
0
ファイル: NumberService.cs プロジェクト: wawan83/antrian
        public static string GetConnectionString(string oldString)
        {
            String connectionString = String.Empty;
            var    nuansaKey        = Registry.CurrentUser.OpenSubKey("Software").OpenSubKey("Nuansa");

            if (nuansaKey == null)
            {
                if (!string.IsNullOrEmpty(oldString))
                {
                    return(oldString);
                }
                MSDASC.DataLinks dataLinks  = new MSDASC.DataLinksClass();
                object           connection = new Connection();
                ((Connection)connection).ConnectionString = Settings.Default.ConnectionString;

                if (dataLinks.PromptEdit(ref connection))
                {
                    connectionString = ((Connection)connection).ConnectionString;
                    Settings.Default.ConnectionString = connectionString;
                }
                return(connectionString);
            }

            RegistryKey key = nuansaKey.OpenSubKey("NCI Medismart").OpenSubKey("3.00").OpenSubKey("Database");

            if (key == null)
            {
                throw new Exception("Tidak bisa buka registry NCI Medismart");
            }

            for (int i = 0; i < 11; i++)
            {
                var value = (string)key.GetValue("key" + i);
                if (!(value.Contains("User ID") || value.Contains("Password")))
                {
                    connectionString = connectionString + value;
                }
            }
            connectionString += string.Format(";Password={0};User ID={1}", Settings.Default.DatabasePassword,
                                              Settings.Default.DatabaseUsername);
            return(connectionString);
        }
コード例 #14
0
        private void btnConn_Click(object sender, System.EventArgs e)
        {
            ADODB._Connection cn;
            MSDASC.DataLinks  dl = new MSDASC.DataLinksClass();

            try
            {
                cn = new ADODB.ConnectionClass();
                cn.ConnectionString = this.txtConnString.Text + ";Provider=SQLOLEDB.1";
                object oConnection = cn;
                if ((bool)dl.PromptEdit(ref oConnection))
                {
                    this.txtConnString.Text = cn.ConnectionString.Replace("Provider=SQLOLEDB.1;", string.Empty);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
コード例 #15
0
        /// <summary>
        /// Get ConnectionString
        /// </summary>
        public string GetConnectionString()
        {
            /*
              Reference DataLinks
               NOTE: Reference
                    C:\Program Files\Common Files\System\Ole DB\OLEDB32.DLL
                    (Was MSDASC.dll)
               SEE:
                    http://support.microsoft.com:80/support/kb/articles/Q225/1/32.asp
             */
            MSDASC.DataLinks dataLinks = new MSDASC.DataLinksClass();
            //note that a reference to:
            //  c:\Program Files\Microsoft.NET\Primary Interop Assemblies\adodb.dll
            //is also required to read the ADODB._Connection result
            ADODB._Connection connection;

            // get a new connection string
            //Prompt user for new connect string
            connection = (ADODB._Connection)dataLinks.PromptNew();
            //read result
            return connection.ConnectionString.ToString();
        }
コード例 #16
0
        private void button3_Click(object sender, System.EventArgs e)
        {
            MSDASC.DataLinks  dataLinks = new MSDASC.DataLinksClass();
            ADODB._Connection connection;

            if (connectionString.Text == String.Empty)
            {
                try
                {
                    connection = (ADODB._Connection)dataLinks.PromptNew();

                    connectionString.Text = connection.ConnectionString.ToString();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
            else
            {
                connection = new ADODB.ConnectionClass();
                connection.ConnectionString = connectionString.Text;

                object oConnection = connection;

                try
                {
                    if (dataLinks.PromptEdit(ref oConnection))
                    {
                        connectionString.Text = connection.ConnectionString;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
        }
コード例 #17
0
		private void button3_Click(object sender, System.EventArgs e)
		{
			MSDASC.DataLinks dataLinks = new MSDASC.DataLinksClass();
			ADODB._Connection connection;

			if (connectionString.Text == String.Empty)
			{
				try
				{
					connection = (ADODB._Connection) dataLinks.PromptNew();

					connectionString.Text = connection.ConnectionString.ToString();
				}
				catch (Exception ex)
				{
					MessageBox.Show(ex.ToString());
				}
			}
			else
			{
				connection = new ADODB.ConnectionClass();
				connection.ConnectionString = connectionString.Text;

				object oConnection = connection;
				
				try
				{
					if (dataLinks.PromptEdit(ref oConnection))
					{
						connectionString.Text = connection.ConnectionString;
					}
				}
				catch (Exception ex)
				{
					MessageBox.Show(ex.ToString());
				}
			}
		}
コード例 #18
0
ファイル: fmExtClientWzdu.cs プロジェクト: san90279/UK_OAS
 private void btnConnectionString_Click(object sender, EventArgs e)
 {
     ADODB.Connection Conn = null;
     String ConnectionString = tbConnectionString.Text;
     MSDASC.DataLinks dataLinks = new MSDASC.DataLinksClass();
     if (ConnectionString == string.Empty)
     {
         Conn = (ADODB.Connection)dataLinks.PromptNew();
     }
     else
     {
         Conn = new ADODB.Connection();
         Conn.ConnectionString = tbConnectionString.Text;
         object TempConn = Conn;
         if (dataLinks.PromptEdit(ref TempConn))
             ConnectionString = Conn.ConnectionString;
     }
     tbConnectionString.Text = Conn.ConnectionString;
 }
コード例 #19
0
        /*private void DownloadLatestVersion()
        {
            Zeus.WindowsTools.LaunchBrowser(URL_LATESTVERSION, System.Diagnostics.ProcessWindowStyle.Minimized, true);
        }*/
        #endregion

        #region Show OLEDBDialog Dialog

        protected string BrowseOleDbConnectionString(string connstr)
        {
            MSDASC.DataLinksClass dl = new MSDASC.DataLinksClass();
            dl.hWnd = this.Handle.ToInt32();

            ADODB.Connection conn = new ADODB.Connection();
            conn.ConnectionString = connstr;

            object objCn = (object)conn;

            if (dl.PromptEdit(ref objCn))
            {
                return conn.ConnectionString;
            }

            return null;
        }
コード例 #20
0
        static void CreateUDLFile(string FileName, OleDbConnectionStringBuilder builder)
        {
            try
            {
                string conn = Convert.ToString(builder);
                MSDASC.DataLinksClass aaa = new MSDASC.DataLinksClass();
                aaa.WriteStringToStorage(FileName, conn, 1);

            }
            catch (Exception ex)
            {
                MessageBox.Show("Error in creation of UDL file - " + ex.Message, "ERROR", MessageBoxButtons.OK);
            }
        }
コード例 #21
0
        /// <summary>
        /// Displays a Connection String Builder (DataLinks) dialog.
        /// 
        /// Credits:
        /// http://www.codeproject.com/cs/database/DataLinks.asp
        /// http://www.codeproject.com/cs/database/DataLinks.asp?df=100&forumid=33457&select=1560237#xx1560237xx
        /// 
        /// Required COM references:
        /// %PROGRAMFILES%\Microsoft.NET\Primary Interop Assemblies\adodb.dll
        /// %PROGRAMFILES%\Common Files\System\Ole DB\OLEDB32.DLL
        /// </summary>
        /// <param name="currentConnectionString">Previous database connection string</param>
        /// <returns>Selected connection string</returns>
        private string PromptForConnectionString(string currentConnectionString)
        {
            MSDASC.DataLinks dataLinks = new MSDASC.DataLinksClass();
            ADODB.Connection dialogConnection;
            string generatedConnectionString = string.Empty;

            if (currentConnectionString == String.Empty)
            {
                dialogConnection = (ADODB.Connection)dataLinks.PromptNew();
                generatedConnectionString = dialogConnection.ConnectionString.ToString();
            }
            else
            {
                dialogConnection = new ADODB.Connection();
                dialogConnection.Provider = "SQLOLEDB.1";
                ADODB.Property persistProperty = dialogConnection.Properties["Persist Security Info"];
                persistProperty.Value = true;

                dialogConnection.ConnectionString = currentConnectionString;
                dataLinks = new MSDASC.DataLinks();

                object objConn = dialogConnection;
                if (dataLinks.PromptEdit(ref objConn))
                {
                    generatedConnectionString = dialogConnection.ConnectionString.ToString();
                }
                else
                {
                    return currentConnectionString;
                }
            }
            generatedConnectionString = generatedConnectionString.Replace("Provider=SQLOLEDB.1;", string.Empty);
            if (
                    !generatedConnectionString.Contains("Integrated Security=SSPI")
                    && !generatedConnectionString.Contains("Trusted_Connection=True")
                    && !generatedConnectionString.Contains("Password="******"Pwd=")
                )
            {
                if (dialogConnection.Properties["Password"] != null)
                    generatedConnectionString += ";Password="******"Password"].Value;
            }

            return generatedConnectionString;
        }